![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | eviking |
For some reason it seems that the change scene method is jumping to the whatever argument was used furthest down in the script. It should be respecting the counter, but it seems to be ignoring it.
For example, on level one you have 2 doors appear - you pick the correct door, you go to level 2 (which is res://Scenes/Stage002_Hallway.tscn However at this point I am always directed to res://Scenes/Stage004_Hallway.tscn So it is skipping over level two and three)
I have tried using variables with preload and load and that is throwing all kinds of odd errors.
extends Area2D
var counter = 0
func _ready() -> void:
pass
func _process(delta):
var bodies = get_overlapping_bodies()
for body in bodies:
if "Player" in body.name:
if counter == 0:
if Input.is_action_just_pressed("ui_spacebar"):
get_tree().change_scene("res://Scenes/Stage002_Hallway.tscn")
counter += 1
if counter == 1:
if Input.is_action_just_pressed("ui_spacebar"):
get_tree().change_scene("res://Scenes/Stage003_Hallway.tscn")
counter += 1
if counter == 2:
if Input.is_action_just_pressed("ui_spacebar"):
get_tree().change_scene("res://Scenes/Stage004_Hallway.tscn")
pass
As always thank you for any help.