I have an enemy spawn script that is supposed to be spawning the enemies in one of four random locations. So it spawns fine in locations 1-3, but for some reason never gets to 4. Here is my code I’m not sure if it will help.
var spawning = false;
var spawnPoint : int;
var theLocation : Transform; Instantiate (theLocation , theLocation.position, transform.rotation);
var level : int;
function Start () {
spawning = false;
level = 1;
cooldown();
}
function Update () {
if(spawnPoint == 1 && spawning){
Instantiate(theLocation,Vector3 (0,-8,0), Quaternion.identity);
spawning = false;
cooldown();
};
if(spawnPoint == 2 && spawning){
Instantiate(theLocation,Vector3 (0,8,0), Quaternion.identity);
cooldown();
spawning = false;
};
if(spawnPoint == 3 && spawning){
Instantiate(theLocation,Vector3 (-8,0,0), Quaternion.identity);
cooldown();
spawning = false;
};
if(spawnPoint == 4 && spawning){
Instantiate(theLocation,Vector3 (8,0,0), Quaternion.identity);
cooldown();
spawning = false;
};
}
function cooldown () {
for (var x = 1; x < 2; x++) {
if (level == 1){
yield WaitForSeconds(2);
spawning = true;
spawnPoint = Random.Range(1,4);
}
if(level == 2){
yield WaitForSeconds(1);
}
spawnPoint = Random.Range(1,4);
spawning = true;
}
}