Game Development Reference
In-Depth Information
The first issue to tackle is the positioning. In the previous chapter, the decision was made to lock the
player into a single screen aspect ratio. While this would allow you to safely hard-code in the label's
location, a better solution is to access the screen size directly. This method also makes it easier to
test without using “Maximize on Play.”
Change the GUI.Label line to
4.
GUI.Label(new Rect(Screen.width / 2, Screen.height / 2,1000,100), finishedMessage);
5.
Save the script, and click Play again.
This time, the label is rendered near the center of the screen (Figure 10-3 ).
Figure 10-3. The Label at half screen width and height
The text, being left justified, reminds you that you will also have to add an offset to the label's
location. Having defined the rectangle as 1000 wide, the offset should be 500.
6.
Do not get out of Play mode.
Change the GUI.Label line to
7.
GUI.Label(new Rect(Screen.width / 2 - 500, Screen.height / 2,1000,100), finishedMessage);
8.
Save the script, change focus by clicking in the Game view, and wait for it to
update and show the recent change.
The rectangle the label is drawn in may be 1000 wide, but the text is obviously left justified inside it.
Fortunately, you will be able to change this.
 
Search WWH ::




Custom Search