Hello, I'm having trouble with a script for Mass Spawning to create a swarm of enemies in a side scrolling shooter game. It respawns but makes more than the intended number. Also they are too closely summoned, so I wanted to add a Wait function before continuing the loop but the code didn't seem to work. Does anyone have suggestions?
//What enemy are we spawning?
var Enemy: GameObject;
//Add regular timer here and rest timer
function Update () {
//Is the enemy already Out?
//Change to timer in future?
if (GameObject.FindWithTag("Enemy") == false){
Wait 0 seconds before triggering the Mass Spawn function
Invoke("MassSpawn", 0);
}
else
{
CancelInvoke();
}
}
function MassSpawn(){
//Set up a loop to add until i =5, loop 5 times, make 5 respawns
for(var i: int = 0; i < 5; i++ ){
//WaitForSeconds(1);
Instantiate(Enemy, transform.position, Quaternion.identity);
}
}