ENUMERATION
PUBLISHED: 9/25/2023
Last updated
PUBLISHED: 9/25/2023
Last updated
ENUM --> a value type that represents a list of named integer constants
CONSTANTS --> fixed values that a program can't change during its execution
--> Using an enum, define enemy types and assign values to each member
--> Using enums, create options for a "Easy", "Normal", "Hard", and "Impossible" difficulty
A enumeration type, also known as an enum, is a value type that represents a group of constants. It is used to assign constant names to a group of numeric integer values. Enums make constant values easier to read.
An enum is defined using the keyword enum
, with all constant names declared inside the curly brackets and separated by a comma.
OBJECTIVE: Using an enum, define enemy types.
By default, if there is no value assigned to the enum members then the compiler will assign an integer value to each member. With the first item having the value 0, the second having the value 1, and so on.
An enum can be accessed using the dot syntax: enum.member
OUTPUT:
To gain access to the integer value from a enum member, you must explicitly convert the member to an int value.
OUTPUT:
Enums create logic to be able to create a drop-down menu so a designer/programmer can select a single drop down item within the inspector.
OBJECTIVE: Using Enums, create options for a "Easy", "Normal", "Hard", and "Impossible" difficulty
Declare and define an enum for the levels the game will contain. Use the default values
Create a variable that will allow the level to be changed from within the Unity Editor.
By declaring a public variable of the enum type Level
, the program will allow that variable to be modified from within the Unity Editor.
| Declare and define an enum for a list of enemy types.
| Each enemy should be assigned an integer value to represent how many points it is worth
| Access the enemy type
| Convert the enemy type to display its point value
| Declare and define an enum for the levels the game will contain.
| create a variable that will allow the level to be changed from within the Unity Editor
| Use a switch statement to display which level has been chosen
Use a to display which level has been chosen.