Game Development Reference
In-Depth Information
Classified intel
In this section, we used GUIContent to contain information of our items and skills, then
passed it to the GUI.Label() function. Basically, if we take a look at each GUI class's
function, we will see that they can take many variables such as Rect , string , Tex-
ture , GUIContent , and GUIStyle . We already know Rect , string , and Tex-
ture . Also, GUIStyle is the name of the style from our MenuSkin object that we cre-
ated, but what is GUIContent ? It is basically a class that contains the necessary variables
(image, text, and tooltip) to apply to our GUI. For example, if we want our button to have
an icon, name, and information when the user rolls over it, we can add the following code:
GUI.Button(Rect(0,0,100,20), GUIContent("My Button Name",
icon, "This is the button info").
The first parameter is the string that will be the text or in our case, it is the button name,
which is seen on the button, and next is the graphic's texture or icon that will also be seen
on this button. The last string is the information that will be stored in this button, which we
call tooltip. We can show this tooltip when the user rolls over this button by calling
GUI.tooltip . This will automatically show the current button's tooltip that the user rolls
over. We will use it in the next section.
Note
For more details about GUIContent and GUI.tooltip , check out the following web-
site:
http://unity3d.com/support/documentation/ScriptReference/GUIContent.html
Search WWH ::




Custom Search