States

Re: Unity 2D Course (Complete Combat System)

I’d like a little more clarification on the EnemyAI script, more specifically

private enum State
    {
        Roaming
    }

What is the use of the “enum” command?
How is “State” handled by unity?
What does the “Roaming” command mean? Are we just identifying this State as “Roaming” as a string, or does “Roaming” hold meaning in Unity?

1 Like

An “enum” allows you to define a set of named constants, which in this case represent the different states that an enemy can be in. The constants are given integer values automatically by the compiler, starting with zero and incrementing by one for each subsequent constant.

In this specific script, the “State” enum is used to define the different states that an enemy can be in. Currently, there is only one state defined: “Roaming.” This means that the enemy is currently wandering around aimlessly, looking for the player.

The “Roaming” command is simply identifying this state as a string, as you mentioned. It does not hold any special meaning in Unity itself; it’s just a convenient way to refer to this particular state within the script.

In summary, the “enum” keyword is used to define a custom data type with a set of named constants, which are used to represent different states that an object (in this case, an enemy) can be in. In this script, the “State” enum defines a single state called “Roaming,” which represents the enemy wandering around aimlessly.

This is what I found, hope this helps!

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms