I use Random.Range(0.5f) to generate a random bool value. And I could cascade IF statements to include 8 possibilities. But what is a better way of doing this? Thanks.
Of course it depends on your circumstances:
int possibilityIndex = Random.Range (0, numberOfPossibilities);
DoPossibility (arrayOfPossibilities[possibilityIndex]);
1 Like
Cascading IF statements works if you need it to do 1 of 8 different things. Switch statements are specifically made for this kind of situation, though.
If you’re just spawning an item (in which it’s 8 variants of the SAME process), DanielQuake has the right idea. Just call a function referencing the number.
Clone this github: GitHub - tucano/UnityRandom: Random library in C# for Unity3D
Provides a “bag” function just what you need