random spawn enemy in random time?

My idea is that the enemies will randomly appear in the left or right direction and the time will count down from 3 minutes. With this in mind, this level can be replayed multiple times and each time the score will be different depending on how many enemies appear.

However, after running a test with a “ratespawn” value of 50, I only got a few enemies after about 10 seconds, and then none of them appeared. I don’t know if I misunderstood the Random function.

If anyone has any ideas please help me.

Thanks everyone.

I have a coin and I toss it 100 times. What result can be? For sure it’s not 50 heads and 50 tails. The chance is 50:50 but the result does not have to.

I think you should have some guaranteed spawn in gameplay, ex. one enemy per three seconds and a random extra chance to spawn 0-2 enemies. Thanks to that you have a steady game flow, some rhythm, and random challenges.

Edit: One thing. There are two Range functions, one requires integers (result is an integer), and the second floats (result is float). So if you want float result type Random.Range(1f, 101f).

1 Like

I understand what you mean. I will try it. Thanks for your opinion.

haha, I know what I did wrong.
nextSpawn += Time.time + spawnRate
it should be: nextSpawn = Time.time + spawnRate

1 Like