Question by
wasicool7 · Apr 09, 2017 at 07:20 PM ·
random.rangespawning-enemies
Unity2D: Creating a random spawn generator that spawns in low and gradually builds up as time pass by.
Hi, I'm trying to create a random spawn generator that spawns in prefabs at a slow paste and gradually increase the spawn rate of how many random objects is being spawned in. Can anyone help me achieve this? Thank you in advance!
Comment
Answer by toddisarockstar · Apr 09, 2017 at 09:19 PM
float pace;
float reduction;
float timer;
void Start () {
//this is the start rate
pace = 10f;
//lower reduction number makes time incriment shrink faster between spawns
// this float should be between 0 and 1
reduction = 0.9f;
timer = pace;
}
void Update () {
timer += Time.deltaTime;
if (timer > pace) {
print ("spawn here...Time untill next spawn:"+pace);
pace=pace*reduction;
timer=0;
}
}