Game Development Reference
In-Depth Information
Figure 8-10. Adding colliders for button objects on the menu
Each button will post a unique notification to the NotificationsManager when clicked, invoking
the kind of response required for the button, if any valid listeners are registered with the
NotificationsManager. To achieve this behavior, a new script should be created and added to each
button as a component—specifically a new class, called GUIEvent . Let's create this script file now,
as shown in Listing 8-4.
Listing 8-4. GUIEvent.cs: Click Detection Functionality for the Button Objects
01 //Posts notification when gui element is clicked
02 //------------------------------------------------
03 using UnityEngine;
04 using System.Collections;
05 //------------------------------------------------
06 public class GUIEvent : MonoBehaviour
07 {
08 //Notification to send when activated
09 public string Notification = null;
10
11 //Check for input
12 void OnMouseDown()
13 {
14 GameManager.Notifications.PostNotification(this, Notification);
15 }
16 }
17 //------------------------------------------------
Search WWH ::




Custom Search