Search Unity

[C#] What is wrong with this enum code

Discussion in 'Scripting' started by pKallv, Jul 29, 2014.

  1. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    Hi,
    New as I am with C# i would like to use enum.

    definition:
    Code (csharp):
    1.  
    2. private enum FourTapStatus {
    3.     NoActivity,
    4.     Selected,
    5.     Finished
    6.  };
    7.  
    I set the enum in Start():
    Code (csharp):
    1. FourTapStatus value = FourTapStatus.NoActivity;
    I then try to use a Switch statement:
    Code (csharp):
    1.  
    2. switch (value) {
    3.     case FourTapStatus.NoActivity:
    4.         print ("NoActivity");
    5.         break;
    6.     case FourTapStatus.Selected:
    7.         print ("Selected");
    8.         break;
    9.     case FourTapStatus.Finished:
    10.         print ("Finished");
    11.         break;
    12.     default:
    13.         print ("Error enum");
    14.         break;
    15.  }
    16.  
    And get the following message:
    Code (csharp):
    1.  
    2. The name `value' does not exist in the current context
    3.  
    I have tried a few things and ended up with this. I am reading about this here: http://www.dotnetperls.com/enum

    Could someone please help me to understand what I am doing wrong?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I guess your "value" variable does not exist in whatever function you're trying to use it.

    --Eric
     
  3. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    Last edited: Jul 29, 2014