var zombie:GameObject; //Set the zombie model in the inspector
var maxZombies:int; //set max zombies in this round
var maxLiveZombies:int; //set max zombies alive at once
private var zombiesThisRound:int = 0; //this is the number of zombies that have spawned this round, alive or dead
private var previousSpawnPoint:GameObject; //this is where the last zombie spawned
void Start()
{
previousSpawnPoint = GameObject.FindGameObjectsWithTag("spawnpoints")[0]; //this will break if you have no spawnpoints tagged "spawnpoints".
}
void Update()
{
while(GameObject.FindGameObjectsWithTag("zombie").length maxZombies) //while zombies need to spawn because there aren't enough on the map and enough zombies haven't spawned yet.
{
var spawnPoints = GameObject.FindGameObjectsWithTag("spawnpoints"); //get a list of all spawn points
var spawnPoint = previousSpawnPoint; //choose a default spawn point
while(spawnPoint == previousSpawnPoint && spawnPoints.length > 1) //keep choosing a random spawn point until you choose one you haven't choosen yet
{
var spawnPoint = spawnPoints[Math.floor(Math.random() * spawnPoints.length)];
}
previousSpawnPoint = spawnPoint; //store where the zombie spawn last
var newZombie = Instantiate(zombie, spawnPoint.transform.position, spawnPoint.transform.rotation); //create the new zombie
newZombie.tag = "zombie"; //tag it as a zombie
zombiesThisRound++; //increase the number of spawned zombies.
}
}
I don't know if this will work. It's close to functional, though. I wrote the whole thing in the browser. Consider it a learning experience getting it to function.
Trending Articles
More Pages to Explore .....