Godot Version
4.2.2
Question
1 = Scene 1
2 = Scene 2
When I change scene when the player enters the area 1st: 1-> 2 works and 2nd: 2->1 works but when I want to go to scene 2 again from scene 1 3rd time 1->2 does not work
Scene1.gd
func _ready():
print(Global.transition_scene)
print(Global.current_scene)
if Global.game_first_loadin == true :
$Player.position.x = Global.player_start_posx
$Player.position.y = Global.player_start_posy
else:
$Player.position.x = Global.player_exit_posx
$Player.position.y = Global.player_exit_posy
func _process(delta):
# print(Global.transition_scene)
change_scene()
func _on_scene_2_transition_body_entered(body):
# print("enter")
if body.has_method("player"):
Global.transition_scene = true
print(Global.transition_scene)
func _on_scene_2_transition_body_exited(body):
#print("exit")
if body.has_method("player"):
Global.transition_scene = false
func change_scene():
# print(Global.transition_scene)
if Global.transition_scene == true:
# Global.current_scene = "living_room"
if Global.current_scene == "living_room":
# Global.current_scene = "stairs"
get_tree().change_scene_to_file("res://sceneTrees/1st_floor/scene2/1st_floor_scene2.tscn")
Global.game_first_loadin = false
Global.finish_change_scenes()
Scene2.gd
func _ready():
print(Global.current_scene)
if Global.game_first_loadin == true :
$Player.position.x = Global.player_start_posx
$Player.position.y = Global.player_start_posy
else:
$Player.position.x = Global.player_exit_posx
$Player.position.y = Global.player_exit_posy
func _process(delta):
change_scene()
func _on_go_back_body_entered(body):
# print("enter")
if body.has_method("player"):
Global.transition_scene = true
func _on_go_back_body_exited(body):
if body.has_method("player"):
Global.transition_scene = false
func change_scene():
if Global.transition_scene == true:
# Global.current_scene = "stairs"
if Global.current_scene == "stairs":
Global.current_scene = "living_room"
get_tree().change_scene_to_file("res://sceneTrees/1st_floor/scene1/1st_floor_scene1.tscn")
Global.game_first_loadin = false
Global.finish_change_scenes()
Global.gd
var current_scene = "living_room"
var transition_scene = false
var player_exit_posx = 1096
var player_exit_posy = 20
var player_start_posx = 30
var player_start_posy = 20
var game_first_loadin = true
func finish_change_scenes():
if transition_scene == true:
if current_scene == "living_room":
# print("check")
current_scene = "stairs"
else:
current_scene = "living_room"
transition_scene = false
The result