Game Development Reference
In-Depth Information
gm = GameObj.GetComponent<GmeMgr>();
};
16. We now implement a method to handle the mouse click as shown in the
following code. Unity will automatically invoke a method called
OnMouseDown()
when the user clicks the mouse, so we will use that for de-
tecting the click. This is one of many methods that the
MonoBehavior
base
class provides for new C# scripts that you create in Unity3D with the new
script wizard:
void OnMouseDown() { };
17. Inside this method, if we have a
GameMgr
script reference, then we will
do two things. We call
gm.SetState()
, and change the state to
eGameState.eGS_Level1
as shown in the following code. This enumer-
ation is defined inside of the
GameMgr
class and corresponds to the game
being in level one. We will investigate how
GameMgr
handles this next. Of
course,
gm
will only be defined if we remember to rename the
MissionMgr
to
Game
as requested earlier in this chapter:
gm.SetState(gameMgr.eGameState.eGS_Level1);
18. We also then set the
GameObject
active flag to
false
. This causes the
object to cease to update. No scripts or components attached to
PopupMainMenu
will run until
active
is set to
true
again. This has the ef-
fect of disabling the pop up (which is what we will want).
Congratulations! This pop up will be created when the
MAIN
scene is loaded, and
when clicked, it will tell the
GameMgr
to change levels to level one.