Wiki

Options

Case Status
Log In

Wiki

Options

 
Home ยป Core Concepts»Variables»Enum Variables
Index
Navigation
Community Wiki

Enum Variables

An Enum Variable can store Enum values. Enums (Enumerations) are an efficient way to define a set of named constants as a type.

E.g., the System.DayOfWeek type defines: Friday, Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday.

This is much more convenient and legible than using 0,1,2,3,4,5,6 to represent the days of the week!

You can define your own Enums, specific to your project. C# example:

1:
2:
3:
4:
5:
6:
namespace Chess
{
    public enum PlayerColor { White = 1, Black = -1 }

    public enum PieceType { King = 7, Queen = 6, Rook = 5, Bishop = 4, Knight = 3, Pawn = 2 }
}

You can now access Chess.PieceType using an enum variable. Then, for example, you could use Enum Switch to branch behaviour based on the piece type.

Playmaker also provides an Enum Creator wizard to generate this code for you ( beta ).

When you create an enum variable you have to further select the specific enum type. The enum type menu lets you explore all the types available in your project. You can poke around in this menu, but most of the time you should have some idea of what you're looking for! Many useful enums are described in the Unity Scripting Reference.

Examples

Day Of Week

 

Tags:

Last modified on 10/18/2017 6:48 AM by User.

  • RSS Feed