Al Heck

Sign in

A dictionary allows me to associate a key with an item in a list. They are written similarly to a list but add an in to the parameter.

We can then add items similarly, just passing an int in the dictionary.

Sometimes, you can’t pass a string. Enums still come in similar to arrays, so how do we get the int value of an enum?

To cast it, we need to add a (int) in front of the variable amount.

This allows us to grab the numerical value of the enum over the string value. This is great for a level selection system.

Let’s say we wanted to create an item class and we wanted to browse through our items using an enum dropdown list. Here’s how we setup the class.

Now we need a database to connect to.

Let’s make a FSM — finite state machine using an Enum (usually with switch statements). Let’s start by creating our enemy state enum.

Let’s begin and have our enemy start the game in a patrolling state.

Create readable selections based off of integer values! For a difficulty selection screen, instead of doing them as int values (0 for easy, 1 for medium, etc), we can use an enum as a variable. Be sure the last value has no comma.

Let’s create a typical inventory system using lists using C#. To start, let’s create a simple item class.

Let’s create a gameobject and attach an item database script to it.

Let’s begin by creating a list using the string variable type since names are strings.

They are the same as arrays but you can populate it dynamically vs arrays, which simply grab all elements. This is how you create a list.

We first identify what type of item will we put into our list (gameobjects, float, int) and then identify it with a variable name.

They are smart variables! Let’s understand what this means.

When it says {get:set}, it means you can get the value and use an = sign to set the new value

When it says {get}, it means you can only grab the value.

Usually, these are established for you in monobehavior, but we can set these in our variable. To do this, we need to create a private variable (in this case, a bool) and it’s automatically set to false.

Then we can run a public bool called IsGameOver underneath this. It’s sort of like a function in the variable section.

What this does is it gets the isGameOver variable an sets the value to a new value.

Events, actions, enable, disable, lots of stuff going on here. How can we simplify this a little and get to basics. Let’s start by creating a capsule and do a simple movement system. I’m going to create a player capsule and add simple controls the old way.

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ

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