Game Development Reference
In-Depth Information
In the
OnGui()
funcion, we irst checked if the
RESTART
buton is clicked by using the
if
statement to check it. If the
RESTART
buton has been clicked, the
Restart()
funcion
will be called and the loading menu will be displayed for the user to wait for the game to
restart. On the other hand, if the player doesn't click on the
RESTART
buton, the game will
show that the menu page depends on the current stage of the page by using the
switch
statement to check for the
e_page
parameters, which are
Page.GAMEOVER
,
Page.
LOCALSCORE
and
Page.SERVERSCORE
. Each case will call the funcion to draw the UI of its
menu, which are the
GameoverPage()
,
LocalScorePage()
, and
ServerScorePage()
.
Next, we created the
GameoverPage()
funcion, which we can divide into three secions.
First, we created the background, then the label for our menu, and then we displayed the
final score, which is
TimeScoreUI.int_currentScore
. Then, we checked if the player
clicked the
SUBMIT
buton. If not, we will have the
SUBMIT
buton and the text ield for the
players to enter their names and post their scores. In the last step, we created the
LOCAL
HI-SCORE
and
SERVER HI-SCORE
buton, which will set the
e_page
parameter to
Page.
LOCALSCORE
and
Page.SERVERSCORE
.
Finally, we created the other two funcions. The
LocalScorePage()
funcion will show the
result of the high-score table from the local machine, and
ServerScorePage()
will show
the result of the high-score table from the server.
Classified Intel
In this chapter, we created the
enum
parameter to check for the menu page.
The
enum
parameter is very similar to the object class that only contains the
Integer
type
or we can say that only
int
type in the Unityscript. In Unity JavaScript or C#, we create
enum
by using the same syntax, which is
enum Page { OBJECT1, OBJECT2, OBJECT3 };
or
enum Page { OBJECT1=1, OBJECT2, OBJECT3 };
.
From those scripts, if we don't assign the integer value to any object, the value of each object
will automaically be assigned, staring from
0
and so on. If we assign the integer
1
to the first
value, then that object value will be
1
instead of
0
and the rest will coninue from
1
and so on.
We can also assign the number for each object manually, such as
enum Page { OBJECT1=2,
OBJECT2=7, OBJECT3=0 };
. This will assign each object to have its own value.
For more details on
enum
, we can go to the following website:
http://msdn.microsoft.com/en-us/library/sbbt4032%28v=vs.80%29.aspx
.