- Home /
C# OnMouseExit Kill/Destroy GUILayout Element
Hi everyone, is there a way to kill or destroy a GUIlayout element? I need a way to get rid of the GUILayout.Labels after the mouse goes over the gameobject that the script is attached to.
Void OnMouseOver(){
GUILayout.Label("someLabel1");
GUILayout.Label("someLabel2");
GUILayout.Label("someLabel3");
}
Void OnMouseExit(){
//Kill GUILayout.Labels
}
Just use a boolean (true or false). Only show labels if something is true like so:
bool showLabel;
void On$$anonymous$$ouseOver()
{
showLabel = true;
}
void On$$anonymous$$ouseExit()
{
showLabel = false;
}
void OnGUI()
{
if(showLabel)
{
GUILayout.Label("someLabel1");
}
}
Answer by Hotshot10101 · Jun 07, 2013 at 05:09 AM
Actually you should do your GUI stuff inside of OnGUI and then just set flags in the mouse methods. Something like this:
bool guiLayoutOn = false;
void OnMouseOver
{
guiLayoutOn = true;
}
void OnMouseExit
{
guiLayoutOn = false;
}
void OnGUI
{
if (guiLayoutOn)
{
GUILayout.Label("somelabel1");
}
}
lol our examples are almost identical XD. I voted you up so your answer will move to the top.
@DangerousBeans Go ahead and accept this answer, it's the same as $$anonymous$$e, and this guy needs karma points.
Thanks for the karma.
I do think it is funny how close our answers are.
Your answer
Follow this Question
Related Questions
C# How to Make Stack of Buttons and Labels not Even 1 Answer
C# Putting a Series of Labels in Between a Series of Buttons 1 Answer
C# Non-Static Member Rigidbody2D.MovePosition 1 Answer
How to make specific text in a string array Bold C# 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers