add train control game
This commit is contained in:
19
scripts/scene_switcher.gd
Normal file
19
scripts/scene_switcher.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Node
|
||||
|
||||
var current_scene = null
|
||||
|
||||
func _ready() -> void:
|
||||
var root = get_tree().root
|
||||
current_scene = root.get_child(root.get_child_count() - 1)
|
||||
|
||||
|
||||
func switch_scene(res_path):
|
||||
call_deferred("_deferred_switch_scene", res_path)
|
||||
|
||||
|
||||
func _deferred_switch_scene(res_path):
|
||||
current_scene.free()
|
||||
var scene = load(res_path)
|
||||
current_scene = scene.instantiate()
|
||||
get_tree().root.add_child(current_scene)
|
||||
get_tree().current_scene = current_scene
|
||||
Reference in New Issue
Block a user