static var tooltip : string
Description
The tooltip of the control the mouse is currently over, or which has keyboard focus. (Read Only).
When you create GUI controls, you can pass in a tooltip for them. This is done by changing the content parameter
to take a custom-made GUIContent object, rather than just passing in a string to display.
When the mouse is over a control with a tooltip, it sets the global GUI.tooltip value to the tooltip you pass in.
If the mouse is not howering over any control, the value is set to the control which has keyboard focus.
At the end of the OnGUI code, you can make a label showing the value of GUI.tooltip
GUI Tooltip on th Game view appears when the mouse is over the button.
You can use the ordering of elements to create 'hierarchical' tooltips:
function OnGUI () {
GUI.Box (
Rect (5, 35, 110, 75),
GUIContent (
"Box",
"this box has a tooltip"));
GUI.Button (
Rect (10, 55, 100, 20),
"No tooltip here");
GUI.Button (
Rect (10, 80, 100, 20),
GUIContent (
"I have a tooltip",
"The button overrides the box"));
GUI.Label (
Rect (10,40,100,40),
GUI.tooltip);
}
using UnityEngine;
using System.Collections;
public class example :
MonoBehaviour {
void OnGUI() {
GUI.Box(
new Rect(5, 35, 110, 75),
new GUIContent(
"Box",
"this box has a tooltip"));
GUI.Button(
new Rect(10, 55, 100, 20),
"No tooltip here");
GUI.Button(
new Rect(10, 80, 100, 20),
new GUIContent(
"I have a tooltip",
"The button overrides the box"));
GUI.Label(
new Rect(10, 40, 100, 40),
GUI.tooltip);
}
}
import UnityEngine
import System.Collections
class example(
MonoBehaviour):
def
OnGUI():
GUI.Box(
Rect(5, 35, 110, 75),
GUIContent('Box', 'this box has a tooltip'))
GUI.Button(
Rect(10, 55, 100, 20), 'No tooltip here')
GUI.Button(
Rect(10, 80, 100, 20),
GUIContent('I have a tooltip', 'The button overrides the box'))
GUI.Label(
Rect(10, 40, 100, 40),
GUI.tooltip)
Tooltips can also be used to implement an OnMouseOver / OnMouseOut messaging system: