Get int value from Enum in Visual Scripting (Unity)

33 Views Asked by At

I'm creating a game in Visual Scripting in Unity. I created an enum in a C# Script because I read that we can't create Enum in Visual Scripting (if someone knows how to do it, I would be very grateful). Here is how I created it:

   public enum Speeds { Slow = 0, Normal = 1, Fast = 2, Faster = 3, Fastest = 4 };
   public Speeds currentSpeed;

Is there an easy way to get the integer value off the enum in Visual Scripting so I can have an equivalent to (int)currentSpeed ?

I tried to make a Switch on Enum but the result is not good and it seems very complicated to redo a simple C# line.

1

There are 1 best solutions below

0
Pekos123 On

It isn't question about unity like more on C# but here is your answer: Just do what you did to currentSpeed. So....

int SpeedsEnumInt = (int)Speeds.Slow;

same if you have currentSpeed:

int SpeedsEnumInt = (int)currentSpeed;