Using The Enum Type

Enums are a powerful tool within games development and computer science more broadly. It allows you to essentially create your own boolean-style list of discreet constants.

Let's say we wanted to be able to record the day of the week in C#. We could create a string variable to hold that, or perhaps hold a number between 0 and 6 in an integer, but we could also make an enum with all of the possible days of the week, then make an instance of that enum to say what day it is today:

enum DaysOfWeek { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }

DaysOfWeek today = DaysOfWeek.Wednesday; // Using enum as a type

As you can see, you can declare one of the potential enum states using [enum].[state], as in DaysOfWeek.Wednesday

This is very useful in character design, as we can limit a character's class, gender, race, starting location etc into a list of possible options, then simply choose one by making an instance of that enum (like the 'today' variable above).

Additionally, you can expose the list you've created with the enum type using the [SerializeField] attrribute:

[SerializeField]
Class characterClass;

This creates a drop-down menu in the Unity Inspector of these different enums!

Last updated