- Home /
How to increase int every 5 waves?
So I'm making enemy spawning system and I want to increase maximum amount of enemy on the scene by 2, every 5 waves. Let's say maximum enemies at the beginning is 3.
int maxEnemies = 3;
and I want to increase it every 5 waves:
Every 5 waves
{
maxEnemies++;
}
How do I say "Every x waves" in Unity?
I think foreach has something to do with it but I don't know.
PS. I want it to be like:
1st increase: every 5 waves 2nd increase: every 5 waves 3rd increase: every 4 waves 4th increase: every 3 waves
I don't want it to be like infinitely every 5 waves.
Answer by Aspect13 · Dec 28, 2018 at 09:23 PM
I figured it out. If anyone would need to do it here's the code:
int waveIndex = 1;
int waveChecker = 5;
int maxEnemies = 3;
if(waveIndex == waveChecker)
{
waveChecker += Random.Range(4, 5);
maxEnemies++;
}
So everytime waveIndex becomes the same as waveChecker, it increases the waveChecker value to be ready for the next check:
1st check: waveChecker is 5;
2nd check: waveChecker is 9 or 10
3rd check: waveChecker is 13, 14 or 15
etc.
Then it increases the maxEnemies value so that we can spawn more enemies. :P
Your answer
Follow this Question
Related Questions
Spawn waves & wait till it's killed, spawn again. 1 Answer
How to make the clones of a zombie continue to clone? 2 Answers
How to increase the spawn rate of an object over time? 2 Answers
ai spawning please help 0 Answers
How to spawn enemies at different locations and avoid overlapping each other 2 Answers