I have a section of code within a game in Unity which is meant to create a series of 20 objects with a 3 in 5 chance of generating a Basic Object (BO), a 1 in 5 chance of generating Special Object 1 (SO1) and another 1 in 5 chance of generating Special Object 2 (SO2). The objects should be generated in a random mix of the 3 types spread throughout the 20 object sequence. However instead of creating a 20 object sequence of a mixture of the objects it creates a 20 object sequence of 1 type of object with the above chances of the sequence being made completely of said objects. Here is my code.
int x = 0;
do
{
var r = new System.Random();
int objectType = r.Next(1, 6);
if (objectType < 4)
{
SpawnBO();
}
else if (objectType == 4)
{
SpawnSO1();
}
else if (objectType == 5)
{
SpawnSO2();
}
x++;
} while (x < 20);
I have tried putting the x++;
within each part of the if
statement but I still get the same result. Any ideas on how I can get it to create a mixture of the objects instead?