me again… but for a different topic:
how can I create an array var so that it appears in the inspector as a popup with array content to choose from.
typical example:
a light has a type var that you can set to Point, directionnal or spot.
I’d like to expose the same thing within my script.
Thanks,
Jean
The light type is an enumeration. An enumeration is an integer that has names applied for each number. Enumerations make it easier to create readable code and efficiently switch between states in a script.
Here is how to write an enumeration and a variable that uses it in javascript:
var bored = false;
var confused = true;
var forumReadTime = 80.00;
enum EnumerationKnowledge {DoesntKnowWhatAnEnumIs = 0, IsLearningAboutEnums = 1, KnowsHowEnumsWork = 2, InventorOfEnums = 3}
var jeanfabresEnumKnowledge = EnumerationKnowledge.DoesntKnowWhatAnEnumIs;
function Start ()
{
while(bored || confused)
{
yield ReadUnityForum();
}
}
function ReadUnityForum ()
{
if(jeanfabresEnumKnowledge == EnumerationKnowledge.IsLearningAboutEnums) jeanfabresEnumKnowledge = EnumerationKnowledge.KnowsHowEnumsWork;
if(jeanfabresEnumKnowledge == EnumerationKnowledge.DoesntKnowWhatAnEnumIs) jeanfabresEnumKnowledge = EnumerationKnowledge.IsLearningAboutEnums;
yield WaitForSeconds(forumReadTime);
}
And yes that code should actually compile and work
there you go!
Strange tho when I search for enum in the api it doesn’t return anything.
Thanks,
Jean
Eric5h5
September 7, 2007, 6:29pm
4
That’s because it’s a language feature, not something specific to Unity. If you like, you can leave out the number assignments, since they are implicit:
enum Button {Start, Stop, Forward, Backward}
–Eric
Enums don’t have to be integers though (at least in C#).
Anyone know if Unity’s JS works the same as C# with enums?
If so, here is some documentation. http://msdn2.microsoft.com/en-us/library/sbbt4032(VS.80).aspx