Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | YPestis |
How can i make to change the scene when all the enemies are dead?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | YPestis |
How can i make to change the scene when all the enemies are dead?
Reply From: | lewis glasgow |
put all enemys in a node2D and call it enemies, assuming when enemies get killed they deleted from the game ( queue_free() )
func _process(delta):
if $enemies.get_child_count == 0:
get_tree().change_scene("your next level")
Reply From: | danielhernandez |
You can add each enemy (I suppose there’s a Enemy scene) to a group, “enemies” for example.
Then, you can check how many nodes there are in the group:
func _process(delta):
var enemies = get_tree().get_nodes_in_group("enemies")
if enemies == 0:
go_to_next_level()
Of course, for this to work, you have to remove the enemies as they die with queue_free().