- Home /
Rounds increasing exteremely fast
Ok here is my script that controls the rounds and spawning of zombies:
var AISpawn : Transform[];
var allEnemies : GameObject[];
static var currentEnemies : int = 0;
var maxEnemies : int = 1;
var minEnemies : int = 0;
var spawn = false;
var spawnTime : float;
static var enemiesDead : int;
var enemies : int;
var round : int = 0;
var roundText : GUIText;
var increaseRound : boolean = false;
function Start()
{
while (true)
{
if(currentEnemies <= 1)
{
currentEnemies = 0;
spawnTime -= 0.1f;
ZombieAI2.speed += 0.3;
increaseRound = true;
maxEnemies += 2;
}
if (currentEnemies <= minEnemies)
spawn = true; // if minEnemies reached start spawning
if (currentEnemies >= maxEnemies)
spawn = false; // if maxEnemies reached stop spawning
if (spawn){ // if spawning enabled create new enemy
// Randomize the different enemies to instantiate.
var obj : GameObject = allEnemies[Random.Range(0, allEnemies.length)];
// Randomize the spawnPoints to instantiate enemy at next.
var pos: Transform = AISpawn[Random.Range(0, AISpawn.length)];
Instantiate(obj, pos.position, pos.rotation);
currentEnemies +=1;
}
yield WaitForSeconds(spawnTime); // free Unity for 2 seconds each loop anyway
}
}
function Update()
{
roundText.text = round + "";
enemies = currentEnemies;
if(increaseRound == true)
{
round+=1;
increaseRound = false;
}
if(spawnTime <= 0.9)
{
spawnTime = 0.9;
}
if(maxEnemies >= 50)
{
maxEnemies = 50;
}
}
when i run the game, the rounds just keep going up??? please help! It is greatly appreciated!!! Thanks!!!
Answer by loftail · Jan 29, 2012 at 01:22 PM
This was fairly simple to spot. The increase in rounds is when thier are no zombies, ie less than one as u said in your script. The error here is that at the beggining of the round, it is less than one always. You must add a timer as well that will chekc this after how ever much time. That will allow your first zombie to spawn, then when the last zombie has died, it will always be checking and the next round will start. Then that function will be called again and it will start again, so i do not think u will come across any errors.
Your answer
Follow this Question
Related Questions
Enemy Spawning 1 Answer
Zombie Round Script Help 1 Answer
Rounds reset 0 Answers
Spawner + AI control 2 Answers
Help with zombies Spawning 5 Answers