How to check to see if Switch Case is true.

Hey guys

I’m using enums + switch statements.

How can I check to see which case is currently true.

Like I wan’t to say something like this:

if (case NanoStage1States.Level1 == true)
do this.

I know I can just put it inside the switch statements but I don’t think I can do that with this:

void OnGUI() {

		pressed = GUILayout.Toggle(pressed, "Toggle me !", "Button");

I’m probably making this confusing. My Question is…how can I make the toggle button appear only when I am in NanoStage1States.Level1?


An enum is a data type, so you have to have a variable of that type.

NanoStage1States currentState;

At some point you must set the value of the currentState variable…

currentState = NanoStage1States.Level1;

If you want to compare the variable to a state, you just use the comparison operator == like you would any other comparison…

if (currentState == NanoStage1States.Level1)
  // do something, such as calling GUILayout.Toggle