Enumerations, understanding how to use them

Ok so I’m new to c# and I found a script/project that uses Enumerations to achieve something similar to what I want as a final product of my game.

I have been trying to figure out Enumerations, and I was watching this video but don’t understand how or if I can Add an Animation trigger to something like

South = animator.SetTrigger(“blah blah”);

I would Assume I would have to Define this in a void Update, further down in the script. Is that right?

https://unity3d.com/learn/tutorials/modules/beginner/scripting/enumerations

Here is my guess, but I haven’t tested this yet though.

public class EnumScript : MonoBehaviour
{
    enum Direction{North, East, South, West};

void Start ()
    {
        Direction myDirection;
       
        myDirection = Direction.North;
    }
   
    Direction ReverseDirection (Direction dir)
    {
        if(dir == Direction.North)
            dir = Direction.South;
//                 Does SetTrigger go here??
//                 animator.SetTrigger("RotateCompassLeft");
//
        else if(dir == Direction.South)
            dir = Direction.North;
//             Or Here, etc?
        else if(dir == Direction.East)
            dir = Direction.West;
//              and here...
        else if(dir == Direction.West)
            dir = Direction.East;
//                  etc....
       
        return dir;    
    }
}

Enumerations are just a handy way of defining a collection of values. There’s nothing special about them. You could just have as easily created 4 ints

int north=0,east=1,south=2,west=3;

And it is essentially the same thing.

I think maybe you’re assuming that Enums are more powerful than they actually are. Imagine if you had this code:

int direction = 0; // 0=north, 1=east, 2=south, 3=west;

void Start() {
direction = 2; //south
}
int ReverseDirection(int oldDirection) {
if (oldDirection == 0) return 2;
//and so on
}

That’s all an enum is, except that it’s more conveniently named. The compiler just transparently turns Direction.North (and so on) into 0 (and so on) in the background. There’s no additional magic to them, really.

So the question about how to use them with animations is a separate questions; it doesn’t have anything to do with enums.

You can make animations trigger just like if you had it stored as an int.

if (olddirection == 1) animator.SetTrigger("TurnFromEast");

///is equivalent to

if (oldDirection == Direction.East) animator.SetTrigger("TurnFromEast");

That makes sense.

Help me please [ CLOSED :( ]Trying to make class like Input class, but for makin custom primitives. - Unity Engine - Unity Discussions

@keenanwoodall I wish I understood what your problem even was, but unfortunately I just starting learning c# about a month ago and don’t understand enough myself.