23 lines
588 B
GDScript
23 lines
588 B
GDScript
extends Node
|
|
|
|
|
|
func goto_room(previous_room: Room, waypoint: Waypoint) -> void:
|
|
print("changing rooms")
|
|
|
|
# for signal
|
|
var prev_name: StringName
|
|
var next_name: StringName
|
|
|
|
prev_name = previous_room.name
|
|
|
|
# wait until previous room is freed
|
|
await previous_room.tree_exited
|
|
|
|
# instantiate next room and set room variables
|
|
var next_room: Room = waypoint.to_scene.instantiate()
|
|
next_name = next_room.name
|
|
next_room.initial_spawn = waypoint.spawn_coordinates
|
|
get_tree().root.add_child(next_room)
|
|
|
|
# notify event bus
|
|
EventBus.room_changed.emit(prev_name, next_name, waypoint)
|