Creating a Dropdown Menu for your Inspector in Unity

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!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

My 90 day journey becoming a Unity game developer: Day-40

Hack a Sat — Talk to me, Goose

Multi-Storefront & Klevu

SOLID Principles — The ‘L’

I design and develop experiences that make people’s lives simple.

How to separate frontend + backend with Rails API, Nuxt.js and Devise-JWT

What is the cloud? | Cloud definition

Join my New Coding Blog!

What To Choose Kodular VS Flutter To Develop A Mobile Application?

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
Justen Chong

Justen Chong

More from Medium

How to Run YouTube in Background on Android and iOS Devices?

Starting at Vodafone Series: Mat Frankum

Starting at Vodafone UK

Online-Hustling #101

online hustling and how to do it right

IOS-Swift language learning notes: Programming in Swift: Functions and Types