I have an info script, where I have name, type etc. Type is an enum, and from 1 script I want to randomly select what type the object is.
But I can’t seem to figure out, how to randomly select an enum in another script…
I have an info script, where I have name, type etc. Type is an enum, and from 1 script I want to randomly select what type the object is.
But I can’t seem to figure out, how to randomly select an enum in another script…
Do a Random.Range() and cast it to the enum type:
Each entry in the enum has its own index value in this case ITEM_01 = 0, ITEM_02 = 1, and so on…
public enum ItemsType
{
ITEM_01,
ITEM_02,
ITEM_03
}
private ItemsType randomType;
void Start()
{
randomType = (ItemsType)Random.Range(0, 2);
}