Unity – Enumerations
Default values:
#pragma strict // The default values are North=0 East=1 South=2 etc... enum Direction{North, East, South, West}; function Start () { var myDirection : Direction; myDirection = Direction.South; // the result is 2 }
Declared values:
#pragma strict // The first value can be declared enum Direction{North=1, East, South, West}; function Start () { var myDirection : Direction; myDirection = Direction.South; // the result is 3 }
#pragma strict // All values can be declared enum Direction{North = 15, East = 18, South = 34, West = 35}; function Start () { var myDirection : Direction; myDirection = Direction.South; // the result is 34 }
#pragma strict enum Direction{North, East, South, West}; function Start () { var myDirection : Direction; myDirection = Direction.North; } function ReverseDirection (dir : Direction) : Direction { if(dir == Direction.North) dir = Direction.South; else if(dir == Direction.South) dir = Direction.North; else if(dir == Direction.East) dir = Direction.West; else if(dir == Direction.West) dir = Direction.East; return dir; }