Multiple GUI.Labels to appear and disappear

How to I make multiple GUI.Labels appear and disappear to have another GUI.Label take it’s place without using coroutines?

1 Answer

1

I suppose you could use boolean values or if you have many different states make an enum, then in the method from where you're creating those labels you do something like

if( myBool )
     GUI.Label(new Rect( 5, 5, 50, 50 ), "Label 1 : True!" );

else
     GUI.Label(new Rect( 50, 50, 50, 50 ), "Label 2 : False!" );

or if you just want the text to change and not make entirely new labels you could just define a string and make the label display that string, and depending on the state you change the string.

bool myBool = true;
string myString = "The String"

GUI.Label( new Rect( 5, 5, 50, 50 ), myString );

if( myBool )
     myString = "True";
else
     myString = "False";

And as said if you have several states that should affect the label(s) you could set up a switch case:)