- Home /
GUI Destroy Label?
Hi, is it possible to destroy a GUI.Label?
Ive tried to put the Gui.label in an variable but theres no variable type GUILabel.
and when I use var test = GUI.Label(...) it gives me the error (Cannot convert void to void).
Thanks
Answer by Eric5h5 · Jun 08, 2010 at 06:31 PM
Simply use a boolean so you don't run the GUI.Label code when you don't need it:
if (showLabel) {
GUI.Label(someRect, "Blah");
}
Thanks but in my case it will not work, because I need to recreate the label with another text, and I cant swap the text while GUI.Label is allready created
@Tobias: I don't really understand what you just said. ;) There's nothing in the code I wrote that would prevent you from using any other text, or swapping it with whatever you like. Just replace "Blah" with a string variable. GUI.Labels aren't objects that are just created once, they are re-drawn every frame (sometimes several times per frame).
Answer by Tetrad · Jun 08, 2010 at 06:48 PM
You can't think of GUI.Label as creating a type. It's probably more accurate to think of it as telling Unity's GUI system to print that label with whatever you pass into it every frame.
So if you need it to change, store off a string to what you want to print, and tell the GUI.Label to print that string instead of hard-coding a particular string.
Answer by BigJac09 · Aug 31, 2011 at 09:02 PM
I got the same problem, my strings was in an array. The value I use was a class member and it always showed the string in position 1. I printed the value used in OnGUI to acces my array and it passed from the right value back to 1. I discovered that it went in fact back to the first nonzero number I initialized my int to.
I solve my problem by setting the member static.
If someone could as an idea as to what was happening...
Hope it helps someone.
Cheers
Edit : Turns out I had set my script to an object it was not suppose to so I really did have two Label on my screen...
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
GUI Scripting button controls 1 Answer
How to make a GUI Label always in the center 1 Answer
Setting Scroll View Width GUILayout 1 Answer
Show enum in a loop in on GUI 1 Answer