- Home /
getting literal value for enum
In every other language that I have used with enums, the enum values are simply constants for numeric values that can be used for anything where a number can be used. However, Unity doesn't like it when using an enum value in math. Consider this:
enum Dir { N, E, S, W };
function lookInDirection(dir:Dir) { var angle:int = dir * 90; // This fails. transform.eulerAngles = Vector3(angle,0,0); }
Is it possible to get the literal value of an enum value (in Javascript)? I saw somewhere that in C# you could simply cast it by using (int)dir, but that doesn't seem to work in Javascript. The following code gives a different error in Javascript:
var angle:int = (dir as int) * 90;
Answer by Eric5h5 · Apr 09, 2011 at 07:26 PM
Use parseInt(dir)
. You can also assign an enum to an integer: var num : int = dir
.
Your answer

Follow this Question
Related Questions
Enum not working properly. 1 Answer
Need some help with a NullReference Error 3 Answers
Enum switch statement error 2 Answers
compare Attack and Defence attribute 1 Answer
Enumerated Colors 2 Answers