ToolTip on Mouse over buttons

Hello eveyone,

I would like to make appear a little tooltip when the mouse cursor is over one of my buttons. Like that little message which appears when the mouse cursor is stationary over one icon…

Hope I was clear. Any help?

Many Thanks.
GC.

for GUI:
http://unity3d.com/support/documentation/ScriptReference/GUI-tooltip.html

for buttons made with own objects, i would use

//for example info.js
static var infotext = "";
function OnGUI () {
	GUI.Label (Rect (Input.mousePosition.x,Screen.height-Input.mousePosition.y, infotext.length * 10, 20), infotext);
        //more conditions for better positions :)
}

button-script:

function OnMouseEnter() {
	info.infotext = "Tooltip Button";  //here: info is the scriptname with the GUI-function and static var
}

function OnMouseExit () {
	info.infotext = "";
}

Thank you very much!! :slight_smile:

Hi rizn… the only problem I have is that the label appears, but behind the button and not on in front of it… :frowning:

just change the order of the draw
make sure you draw the tooltip after the button

It’s actually really weird,
in my onGUI i have this:

windowRect = GUI.Window(0, windowRect, buildMainButtons, “Tool Box”);

and the function buildMainButtons is devoted to build the buttons inside the windows. So, inside the buildMainButtons I have:
if (GUI.Button (Rect (Sx,Sy, 35,35), GUIContent(“”,“Create a new Room”) , “B_NEW”)) { //Function to set a new world
SendMessage(“B_NEWOnMouseOver”, SendMessageOptions.DontRequireReceiver);
renderRoom = !renderRoom;
mainObject.GetComponent(MeshRenderer).enabled = renderRoom;
GUI.UnfocusWindow ();//Deselect chat

}
GUI.Label (Rect (Input.mousePosition.x,Screen.height-Input.mousePosition.y, lastTooltip.length * 10, 20), lastTooltip);

but there is now way the Labels shows up :frowning:

I’ve found the error but it is still behind the button I’m rendering… rather I put the label before or after the if (GUI.Button…) doesn’t make any difference. I am actually using a GUI.skin, does it affect the tool tips?

GC.

please check this example.
its using a guiskin without problems. and it shows a window with a button because of the ‘buildMainButtons’-function.
here, the button has a tooltip.

private var windowRect : Rect;
var mySkin : GUISkin;

function buildMainButtons (){
	GUI.Button (Rect (10, 80, 100, 20),GUIContent ("I have a tooltip", "Tooltip"));
	GUI.Label (Rect (10,40,100,40), GUI.tooltip);
}

function OnGUI () {
	GUI.skin = mySkin;
	windowRect = GUI.Window (0, Rect (10, Screen.height - 100 - 20, 600, 100), buildMainButtons, "theWindow");
	
}