Hi everyone, I want to write a piece of code that spawns enemies in my game. I want it to have a few possible outcomes, each spawning a different kind of enemy. The problem is I want the chances of some of the enemies appearing to be greater than others so Random.Range won’t do. I also need to be able to modify the probability of certain types of enemies spawning at runtime to control the difficulty.
I’m still kind of new to Unity and I have no idea how I could do something like this.
You still use Random.Range…
int randNumber = Random.Range(0,100);
if(randNumber<30){
// 30% chance of this occurring
}
else if(randNumber<90){
// 60% chance of this occurring
}
else if(randNumber>=90){
// 10% chance of this occurring
}