Enums

Learn to use enums to improve code readability, reduce errors, and define named constants.

Introduction

In C#, an enumeration (or enum) is a value type that defines a set of named constants. Developers use enums to represent a set of named values, such as a set of options or a set of states. In Unity, enums can define different states for a GameObject or different types of items in a game. Let’s discuss the ways to use enums in Unity using C#.

Declaring and using enums

To declare an enum in C# with Unity, we use the enum keyword, followed by the enum’s name and a set of named values in brackets. Here’s an example:

Get hands-on with 1200+ tech skills courses.