- Home /
Display tooltips for objects in scene
Hello,
I've got a number of objects in a scene, which when clicked on display buttons (drawn with GUI.Button). The buttons are created in the scripts of the individual objects. I've also got a central, controlling object in the scene, which displays a tool-tip at the bottom of the screen. I'd like to display a tool-tip through this object when the user hovers over the buttons of the individual objects. Can anyone get me started in doing this?
Thanks for reading
Answer by SergeantBiscuits · Apr 24, 2013 at 10:23 AM
In your central control object script, make a 'static' variable. This will make it accessible by any script in your scene. (javascript):
static var tooltipText : String;
Now in other scripts you should be able to do this:
ControlObjectScript.tooltipText = "This is now the tooltip text.";
Hope that helps!
Note that 'static' variables don't show up in the inspector... for some reason.
Thanks $$anonymous$$antBiscuits. Think I'm doing something wrong here, as one of the tooltips is permanently displayed, rather than just when the mouse is over the button. The other tooltips don't respond to mouseover. Any ideas?
This is declared at the beginning of the script:
public static string toolTipText;
This is the Button
if(GUI.Button(turretRepairButton, new GUIContent("", ControlObjectScript.toolTipText = "Repair a damaged turret, or restore a destroyed turret"), "TurretRepairButton"))
This is the tooltip
GUI.Label(new Rect(0, tooltipYPos, tooltipWidth, tooltipHeight), toolTipText, "toolTip");