- Home /
Increasing spawn rate over time
I am trying to figure out how to increase the spawn rate of my prefab over time. So as time goes on the game will get harder because the spawns will get faster. Thanks everyone in advance for taking the time to help :).
Transform spawnLoc;
public GameObject [] grumpyMoles;
public bool spawn;
void Awake()
{
spawnLoc = this.gameObject.transform;
StartCoroutine (SpawnTimer (15));
}
void Update()
{
Spawner ();
}
void Spawner()
{
if (spawn)
{
Instantiate(grumpyMoles[Random.Range(0,grumpyMoles.Length)], spawnLoc.position, spawnLoc.rotation);
spawn = false;
}
}
IEnumerator SpawnTimer(float waitTime)
{
while(true)
{
yield return new WaitForSeconds (waitTime);
spawn = true;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Intensifying rate over time... 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
2d game for my first unity project. 1 Answer
Rhythm Game Out of Sync (C#) 1 Answer