Unity Select Level using enum

Niraj Karki
2 min readSep 10, 2023

Objective: Create a program that lets you select easy, medium, or hard through the Inspector. When you hit the space key, it will print out the selected difficulty. Example: “You selected Easy.” You should be able to change the difficulty at runtime.

Now set up your scene with three buttons representing easy, medium and hard. Also add a text object in the scene to display the level you selected when the space key is pressed.

Now create a new script and create an enum outside the monobehaviour class that contains easy, medium and hard selectable.

Now inside the script, create an enum variable as well as TextMeshProUGUI variable to display text on screen.

Inside Update, create a condition to check the space key press and when pressed, display the selected level using the TextMeshProUGUI variable.

Then create three public functions representing each level and on those function call change the level accordingly.

Then inside unity, assign that script to a gameobject in hierarchy. Also create three buttons and create a listener to On Click event of the button which calls the Function to change level.

And this is the Final result.

--

--