Game Development Reference
In-Depth Information
If you require the same font at different sizes, drag multiple copies
of the .ttf file into the Project and give them different names, such as
myFontSmall or myFontBig, and set their individual sizes.
Step 23. Select the Main Camera; in the Inspector, set the Font value
of My Style to the font just added.
Step 24. Open mainmenu.js. Modify as shown in Listing 6.3 .
Listing 6.3 Applying a Style to a GUI Object
var myStyle: GUIStyle;
function OnGUI () {
GUI.BeginGroup (
Rect (Screen.width / 2 — 50, Screen.height / 2 — 50,
100, 150));
GUI.Box (Rect (0,0,100,150), "Main Menu", myStyle );
GUI.Button (Rect (10,40,80,30), "Play", myStyle );
GUI.Button (Rect (10,70,80,30), "Help", myStyle );
GUI.Button (Rect (10,100,80,30), "Quit", myStyle );
GUI.EndGroup ();
Step 25. Play. The menu will have the new font applied.
Step 26. Note that the buttons are now just text. When you apply
a style, all the other stylings disappear. It's now up to you to set the
background images for the buttons and other GUI objects. The default
background and color are set in the Normal value of the style. Create
a test image to use as the background. For now this can just be a
plain black or white .jpg file. Add it to the Project and then set the
Background value for Normal to this image. Play. The button now has a
font and color.
Step 27. The button can be made to change when hovered over,
pressed, and so on. This is done by setting the values of the other style
attributes appearing below Normal in the Inspector. Note that you
cannot just set the font color for these. You must set a background
texture and a color, as otherwise they do not activate. Try setting the
Hover values. Play.
Step 28. In the last step, creating values for button hovering
will also have set them for the entire menu box. This may be an
undesirable effect. You can create multiple GUIStyles and add them
to whatever elements you see fit. In this case, create a separate style
for the main menu GUI.Box and change it so the Hover values do not
Search Nedrilad ::

Custom Search