- Home /
GUI OnMouseEnter popup. text String is layering for multiple game objects?
Hello Everyone,
Sorry if that title is a little confusing.
I am trying to create a script that I can attach to multiple gameobjects in a scene, which will, when the mouse is hovered over them, make the game object change colors and create a GUI label with some game object specific text. This works just fine for one gameobject, but when I add the script to multiple game objects and assign them different text, when I mouse over them, it is layering all the different lines of text on top of each other in the GUIlabel. So, if I have two object and the text reads "Cube 1" and "Cube 2", when I mouse over one, it renders both labels on top off each other.
Hope that makes at least a little sense. Thanks in advance for any help. I am sure this is something simple that I am just not looking at.
Also, I am a total programming noob, so take it easy on me :)
Here is the script...
var mySkin : GUISkin; var text : String; static var isHovering = false;
function OnMouseEnter(){ renderer.material.color = Color.green; isHovering = true; } function OnMouseExit(){ renderer.material.color = Color.white; isHovering = false; } function OnGUI(){ GUI.skin = mySkin; if(isHovering){ GUI.Label (Rect(400,300,180,60), text); } }
Answer by Eric5h5 · Jan 17, 2011 at 09:18 PM
When a variable is static, that means only one instance of it can ever exist. So when isHovering is true for one script, it's true for them all. Basically you shouldn't use static variables unless you actually mean for it to have one instance.
Hah! I didnt know that but it makes perfect sense. I was really only using the static variable so I didnt have to look at the check box in the editor...
Thanks so much for the help and the quick response!