Game Development Reference
In-Depth Information
18. We add two public
Texture
references in this script. This allows the pro-
grammer to associate an
On
and
Off
texture for the button. When the mouse
is over the button, the
On
texture will be displayed. When the mouse is not
over the button, the
Off
texture will be shown:
Public Texture On;
Public Texture Off;
19. We keep references to the object named
Game
in the scene. We also keep a
reference to the
gameManager
script attached to this. These are cached in
the
start
method.
20. In the
Update()
loop of the button GameObject, we compare
prevTick-
ButtonState
with
ButtonState
:
PrevTickButtonState = ButtonState;
21. In the
OnMouseDown()
method of this GameObject (mouse down on the
button), we call the
Dispatch()
method, which iterates through all of the
buttonResponses
in the action list.
22. The
Dispatch()
method is where the brunt of the work for the button oc-
curs. It loops over all of the actions in the action array (from
0
to
Count
):
for (int i= 0; I < actions.Count; i++)
{
popupResponse r = actions[i];
}
23. A
switch
statement is used to selectively update the logic of the button
based on the type of action in the actions array in each slot. Each potential
popupAction
has its own implementation in this block:
switch(r.action)
{
// each case() implements a different
behavior
}
24. The case for
LoadLevel 1
,
LoadLevel 2
, or
LoadLevel 3
will use
the
GameMgr
component reference, and set the
GameState
in the
GameMgr