Game Development Reference
In-Depth Information
Listing 8-4 and its general mechanics should look familiar now. If not, then jump back to Chapter 3
to consider the NotificationsManager, as a refresher. Add an instance of this class to each button
object, assigning the Notification member to a unique string describing the event to be generated
for that button instance. I've used the strings: HideOptions , ExitGame , LoadGame , RestartGame , and
SaveGame . You don't need to use these names exactly for your own functions; but remember, these
names (whatever they are) should match the names of functions elsewhere that are intended to
handle the events when they happen through the NotificationsManager (see Figure 8-11 where the
GUIEvent component is assigned to button objects).
Figure 8-11. GUIEvent components are added to button objects in preparation for click detection and response
Before proceeding further to handle button clicks, I recommend testing the click-detection code
for your buttons to make sure they do actually detect clicks when they happen, as they should do.
You can achieve this easily by inserting a Debug.Log statement inside the OnMouseDown function of
GUIEvent, for example. If you've added a GUIEvent component but find that no button press is
detected, make sure your button has a collider component with depth in all three axes (not just two),
and also that your buttons and colliders are completely in front of the GUI camera. That is, no part
of the colliders should appear behind the camera. Otherwise, the click will probably not be detected
(see Figure 8-12 ).
Search WWH ::




Custom Search