- Home /
How to slow down my spawn rate?
I am working on a part of a script that will run a countdown timer, when the timer reaches zero it will call a function that spawns a set amount of enemies (in this case 10)
function FixedUpdate()
{
timer -= Time.deltaTime; // Count down the time in seconds on timer
if(timer <= 0)
{
timer = 0;
Debug.Log("New wave started");
StartNewWave(); //start the new wave!
}
}
//start the new wave
function StartNewWave()
{
//Set the GUI
UpdateGUI();
while (enemyCount <=9)
{
//spawn the enemies
SpawnNewEnemy();
}
}
That all works but my issue is that they spawn incredibly close together. The update function is what is determining their spawn rate. I want them to be more spaced out, like if I could call fixed update every half a second. The results are similar when using regular update but is looks sloppier and either way it isn't doing what I want.
I tried putting a yield WaitForSeconds (0.5); right above my SpawnNewEnemy(); call but when I did that I ended up spawning WAY too many enemies. I'm not entirely sure why.
Can anyone think of a solution to this?
Answer by getyour411 · Apr 13, 2014 at 01:17 AM
Use coroutine or InvokeRepeating, FixedUpdate should be used only when the functionality requires it (typically phyics) and this does not; search UA/Google for examples of InvokeRepeating and Coroutine
Your answer
Follow this Question
Related Questions
gradually raise moving speed but got different results on different devices 1 Answer
Changing the spawn rate 0 Answers
How to change the speed of an audio clip? 1 Answer
Change movement speed based on rotation 0 Answers
Forward too slow 1 Answer