i found an older post (last april) that says you have to use enums through c# but that javascript would be supported in the next major release. did that make 1.6?
There are some limitations to this - for example, arrays of enums will not show up in the inspector like, say, an array of strings - but that’s the jist of it.
If you see an integer displayed in the inspector, first make sure you’ve explicitly declared the type of the variable ( : Mode, or whatever your enum type is called) and if that doesn’t work, restarting Unity fixes everything
works like a charm and indeed it didn’t at first. i had it declared correctly but it was a relaunch that got it working. gotta remember that one. thanks again!
Actually you only have to deselect the object in the inspector and select it again. (Right now Unity doesn’t auto update the inspector when a type changes from int to enum, since it internally is treated in the same way.)
Enums are used to give names to a set of constants. So, for example, defining enum WindowState {Open, Closed}; would allow you to have variables of type WindowState which can be assigned the values WindowState.Open or WindowState.Closed. That’s generally preferable to having an int or string variable to which you assign arbitrary values, as it makes it harder to accidentally use a value which isn’t valid.
It has nothing to do with data encapsulation or efficiency. It’s solely to do with putting human-readable names onto values, and making sure you can only use them as intended.
Well I guess in your example it would be easier to use 1 boolean, especially as a window can’t be closed and open at the same time, but I think I know what you mean.
Sure, but it might be clearer to label it with something which explains what it does when it’s used as a parameter to a function. For example, see SendMessageOptions, used as a parameter to SendMessage. If SendMessage took a bool as its last parameter, it’d be much more difficult to tell what it does at a glance.
And if you have three or more values, it’s obviously even more meaningful.
when i couldn’t get it working i had it as an int. in the inspector i had to enter 0, 1 or 2 depending on what i wanted my script to do. someone else would have to look at my script and hope i commented.
instead with enums, i now have a pull down in the inspector and i can select MouseXandY, MouseX or MouseY.