Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ShamanHead |
When I start game, script work:
func _ready():
$Play.connect('pressed', self, 'play');
$Settings.connect('pressed', self, 'settings');
$Exit.connect('pressed', self, 'exit');
func play():
get_node('/root/Global').goto_scene("res://levels/1.tscn");
func exit():
get_tree().quit();
func settings():
get_node('/root/Global').goto_scene("res://levels/main_menu/settings.tscn");
Global.gd:
var current_scene = null
func _ready():
var root = get_tree().get_root()
current_scene = root.get_child(root.get_child_count() -1)
func goto_scene(path):
call_deferred("_deferred_goto_scene", path)
func _deferred_goto_scene(path):
current_scene.free()
var s = ResourceLoader.load(path)
current_scene = s.instance()
get_tree().get_root().add_child(current_scene)
get_tree().set_current_scene(current_scene)
But when I change the 1.tscn to first scene, buttons not work.