Hello there. So for like 3 months of been doing unity bolt and saw something about enums. Could someone dumbify this for me? Like whats an example you could use this for? Does it allow you to change the values of components? Or am I a mile off? Thanks for you time.
Check this out : Enumerations - Unity Learn
1 Like
Generally they make it easier on programmers because they help explain what values mean with descriptive names. For example, without enums you might have some code like this:
private int myCharacterClass = 0;
//0 - not set
//1 - warrior
//2 - mage
//3 - thief
//4 - ninja
public void SetClassMage()
{
myCharacterClass = 2;
}
But then wherever you use myCharacterClass you’d need to remember what each value for it means. With enums though it can look like this:
public enum CharacterClass { NotSet, Warrior, Mage, Thief, Ninja };
private CharacterClass myCharacterClass = CharacterClass.NotSet;
public void SetClassMage()
{
myCharacterClass = CharacterClass.Mage;
}
3 Likes
Aah OK that makes since. Thanks!
1 Like