Creating a Dropdown Menu for your Inspector in Unity

Justen Chong
2 min readMay 11, 2021

--

This can be done very simply using enums. I could get into what exactly enums are and what they do, but that would make this article too long and if you’re anything like me then you’re going to want the quickest answer so here we go.

First, define your enums. This is done outside of any methods and can be done outside of your class, but I included it in the class so I can make them private. Make sure to pay attention to the syntax as it is different from a class:

Now, create your enum variable as a global variable as either Public (which is bad practice) or a SerializedField.

And voila! You’re done! It’s that easy. Why would you use this? Well, enums are constants which means that the data cannot be mutated or changed after declaration during runtime. This can be very useful when there’s some kind of parameter/variable that your code relies on and you don’t want/need to change during runtime.

Here’s an example of this in action in my 2d Space Shooter game from GameDevHq. This example adds the correct component to the player as a powerup based on which enum is selected in the inspector:

Another tool in the toolbox!

--

--

No responses yet