Destroy function destroying only one object and not destroying his clones
Hello i'm new to Unity and i'm having trouble with some coding. I'm developing a tower defense idle game. My problem is i need to destroy all my enemies when my tower hp reaches 0. Then i will be spawned the last wave i was able to beat. But only one or 2 enemies are being destroyed and some remain on the screen and either get destroyed by the tower adding gold or hit it reducing the hp before the new wave spawn.
Here is the code i'm using :
void Update() {
if (TowerHp.Hp <= 0)
{
if (!run)
{
run = true;
TowerHp.Hp = TowerHp.startHp;
waveSpawner.EnemiesAlive = 0;
waveSpawner.waveIndex-=2;
Destroy(gameObject);
return;
}
else
{
run = false;
}
}
You need to learn about Event and Singleton $$anonymous$$anager
Then these stuff will be like kiddo stuff
Your answer
Follow this Question
Related Questions
GameObject.Destroy(gameObject); Not Working? 0 Answers
[SOLVED] How to destroy a cloned object if it object colliding with another cloned object ? 1 Answer
[noob] I have a script that theoretically should manage movement of a 2D GameObject... 1 Answer
Objects are not getting destroyed [I fixed on my own] 1 Answer
Destroyng all childs of an object 1 Answer