Game Development Reference
In-Depth Information
3.
From the GameObject menu, Create Other, select GUI Text.
4.
The text “Gui Text” turns up in the center of the Game View.
5.
Name it Bunny Count .
6.
Turn on “Maximize on Play” at the top right of the Game view.
7.
Click Play.
The text remains the same size even when the game window changed size. As a default, the text
object stays in pixel size.
8.
Stop Play mode, and check out the object's Position transforms.
It uses X/Y screen space. Z can be used to order GUI objects in z space (back into the viewport)
when ambiguity exists. The position value is in unit values; 1 equals 100% of the screen width and
height.
9.
Set its X Position value to 0.85 .
The text shifts to the right, showing that 0 is on the left and 1 is on the right for the X Position.
10.
Set its Y Position value to 0.95 .
The text shifts to the top, showing that 0 is on the bottom and 1 is on the top for the Y position.
11.
Set the Font Size to 30 .
12.
Change its Color to a nice orange.
The most logical place to put the controlling code is on the Scorekeeper script.
1.
Open the Scorekeeper script.
2.
Add the following variable:
public GameObject bunnyCounter; // GUI Text object
Inside the UpdateCount function, below the print line, add the following:
3.
bunnyCounter.guiText.text = "test";
Comment out the print line.
4.
5.
Save the script.
6.
Select the Game Manager, and drag the Bunny Count object onto its Bunny
Count parameter.
Let's try a quick test.
Change the bunnyCounter.guiText.text line to:
7.
bunnyCounter.guiText.text = currentBunCount; // change the gui text's text
 
Search WWH ::




Custom Search