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;
}
}
↧