- Home /
what is an enum ?
hi guys can you please break down and tell me what enums do please be very specific :) thank you very much in advance :)
Answer by Ashkan_gc · May 01, 2011 at 06:27 PM
enum is a keyword that allows you to declare an enumeration. an enumeration is a set of names for valeus. for example
enum Dificulty {easy,normal,hard};
then you can declare variables of type Dificulty and set it's value as easy/normal/hard
Dificulty d = Dificulty.easy;
enums make your program more readable and help you to don't set integer values incorrectly. remembering easy is easier than remembering 0 or 1. a complete reference is available on MSDN [here.][1]
as you can read there the value is easy is 0 and normal 1 and hard 2. values are increased by one and you can set the values to numbers that you want. the type is a constant integral type. by constant i mean that you can not change the value of Dificulty.easy after defining the enum.
unity uses enums for sending constant values to functions. you can see enums usefulness from Input.GetMouseButton() i always froget what number is for what button but if it had an enum like
enum MouseButton {left,middle,right};
then it was easy to set this just like KeyCode and other available enums.
using enums in javascript is the same but i don't know how to define them in js.
hope this helps.
[1]: http://msdn.microsoft.com/en-us/library/sbbt4032(v=vs.80).aspxenter code here
Answer by FLASHDENMARK · May 01, 2011 at 06:25 PM
I think that this site explains it:
it's a good description but when someone asks a question about enums and tells us to be specific you should try to at least $$anonymous$$ch it in the language that we use in unity and not in general. having a game specific example and examples from the docs could be helpful too.
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