Nerd For Tech
Published in

Nerd For Tech

Adding a simple Drop-down Field in the Inspector

Previously we had to set an ID for the Power Up in the Inspector, let’s see how we can create a simple Drop-down Field for our options by introducing an enum variable type that is restricted to a set of values.

Enum

Short for Enumeration, an Enum is a user-defined keyword that allows you to declare a set of named constants called Enumerators. Enumerators are set of names for values.

They restrict the values that the enum variable can take and are a constant rather than a number, increasing readability of the source code.

First we create a private variable of type Enum. To access it in the Inspector we declare it into a private member variable called ‘powerUp’ of type PowerUp.

Enumeration to Integer

One of its benefits is that it automatically stores a value for each constant we add.

Now we can remove the ‘_itemID’ variable we used at first and instead pass one of the enum constants as an integer inside our switch() method.

Previous | Next

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store