How do i locate The last node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Si Disap

I made a node with enemies node as the children of it, I want to make that if player already killed/freed all the enemies it will move a label node to the last enemy node position that get killed.

Here’s my scene:
Level1

Label
Enemies

Slime1
Slime2
Slime3
Slime4
Slime5

Enemies is a node2D
Slimes are Area2D

:bust_in_silhouette: Reply From: Gluon

It would depend on some things in your game for example will there be different numbers of enemys or will it always be five?

One possible way this could work would be to have a script on the Enemies node and a script on each slime node. In the slime node when it is killed send out a signal to say it died and in the enemies node have a script listening to those signals which counts how many times an enemy has been killed. If the signal also sends the slimes global position then when the enemy script detects the last one was killed it could use the global position to add the label.

Oh yeah my bad, Slime 1-5 are the same node, just duplicated, they all have the same script, each of them are placed differently in the scene, and player can choose to kill which slime first. I’ll try your suggestion, Thank you so much!

Si Disap | 2022-05-18 16:10