Search Unity

[Javascript] Convert int to enum of enumerated data type

Discussion in 'Scripting' started by paladin_knight, Mar 26, 2012.

  1. paladin_knight

    paladin_knight

    Joined:
    Aug 16, 2011
    Posts:
    8
    I have the following code:
    Code (csharp):
    1.  
    2. enum LightNum{
    3.     LIGHT01 = 0 ,//TRAFFIC 01 OBJECT
    4.     LIGHT02 = 1,//TRAFFIC 02 OBJECT
    5.     LIGHT03 = 2,//TRAFFIC 03 OBJECT
    6.     LIGHT04 = 3//TRAFFIC 04 OBJECT
    7. };
    8. var currentLight : LightNum;
    9. var nextLight : LightNum;
    10.  
    I would like to know if I want to shift the nextLight using arithmatic like :
    Code (csharp):
    1.  
    2. nextLight = nextLight + 1;
    3.  
    How can I convert from enum to int and into to enum?

    Thanks.:)
     
  2. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    parseInt(nextLight.LIGHT01);
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,209
    You don't need to convert anything, you can just do "nextLight += 1". Enums are defined without a ";" after the brace, by the way. (It doesn't result in an error, but it's not doing anything and isn't necessary.)

    --Eric
     
  4. paladin_knight

    paladin_knight

    Joined:
    Aug 16, 2011
    Posts:
    8
    Thanks a lot for your help.
     
unityunity