Select Page

I am trying to allow one script to change it’s random number generator based on how many values are stored inside the Enum. This will never change during run time but will allow me to remove any magic bullets from the code it’s self. Luckily, the Enum is based on int so a .Length command will work.

private int enumlength = System.Enum.GetNames(typeof(TileType)).Length;

The end result will be Random.Range(0, getEnumLength()). If the Enum has two values it will end up returning either a 0 or a 1 value. I can then check on which conditions that will fall under in the following code. This will be perfect.