- Home /
Spawn Script Issue
I have made a spawn script and it has a few issues... Could someone please help me? The Problem is that it uses 'ActiveRecursively' because for my attack script I make it when an enemy has zero health it is not active. But when It starts more than 1 enemy starts and once they die and the next wave come they glitch out a bit when there health is zero.
Here is the Code: var enemy : GameObject; var enemy2 : GameObject; var enemy3 : GameObject; var enemy4 : GameObject; var enemy5 : GameObject; var enemy6 : GameObject; var enemy7 : GameObject; var enemy8 : GameObject; var enemy9 : GameObject; var enemy10 : GameObject; var enemy11 : GameObject; var enemy12 : GameObject; var enemy13 : GameObject; var enemy14 : GameObject; var enemy15 : GameObject; function Update(){ if (enemy.active == false){ Spawn(); } if (enemy2.active == false){ Spawn(); } if (enemy3.active == false){ Spawn(); } if (enemy4.active == false){ Spawn(); } if (enemy5.active == false){ Spawn(); } if (enemy.active == false){ Spawn(); } if (enemy.active == false){ Spawn(); } if (enemy6.active == false){ Spawn(); } if (enemy7.active == false){ Spawn(); } if (enemy8.active == false){ Spawn(); } if (enemy9.active == false){ Spawn(); } if (enemy10.active == false){ Spawn(); } if (enemy11.active == false){ Spawn(); } if (enemy12.active == false){ Spawn(); } if (enemy13.active == false){ Spawn(); } if (enemy14.active == false){ Spawn(); } if (enemy15.active == false){ Spawn(); } } function Spawn (){ if (enemy.active == false){ enemy2.SetActiveRecursively(true); } if (enemy2.active == false && enemy.active == false){ enemy3.SetActiveRecursively(true); } if (enemy3.active == false && enemy2.active == false){ enemy4.SetActiveRecursively(true); } if (enemy4.active == false && enemy3.active == false) { enemy5.SetActiveRecursively(true); } if (enemy5.active == false && enemy4.active == false){ enemy6.SetActiveRecursively(true); } if (enemy6.active == false && enemy5.active == false){ enemy7.SetActiveRecursively(true); } if (enemy7.active == false && enemy6.active == false){ enemy8.SetActiveRecursively(true); } if (enemy8.active == false){ enemy9.SetActiveRecursively(true); } if (enemy9.active == false){ enemy10.SetActiveRecursively(true); } if (enemy10.active == false) enemy11.SetActiveRecursively(true); if (enemy11.active == false){ enemy12.SetActiveRecursively(true); } if (enemy12.active == false){ enemy13.SetActiveRecursively(true); } if (enemy13.active == false){ enemy14.SetActiveRecursively(true); } if (enemy14.active == false){ enemy15.SetActiveRecursively(true); } }
Arrays are your friends. Use them. I have no idea what you tried to do with the Spawn() function but it should look a lot more like this (c#):
public GameObject[] Enemies;
void Update()
{
for (var i = 0; i < Enemies.Length; i++)
{
if(Enemies[i].active == false) Spawn(i);
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
SendMessage setName has no receiver! 1 Answer
Wierd error messages concerning audio play and pause? 1 Answer
Error CS1502 Help! 1 Answer
Script Error 4 Answers