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");
Debug.Log(pressed);
}
I'm probably making this confusing. My Question is...how can I make the toggle button appear only when I am in NanoStage1States.Level1?
Thanks!
Answer by Dave-Carlile · Sep 11, 2015 at 06:17 PM
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
}
Thanks a lot! Exactly what I was hoping for, works perfectly.
Your answer
Follow this Question
Related Questions
How apply something like the "!" Operator to an enum? 2 Answers
OnGui() Causing lag, am I doing it wrong? 1 Answer
How can I use an "Enum e" I passed from another script in an If or Switch Statement 1 Answer
Null Reference with ifstatements accessing enum types. 2 Answers
Enumaration error CS1025: Single-line comment or end-of-line expected 1 Answer