Game Development Reference
In-Depth Information
The
Poster
class features a public member variable
Notifications
, which keeps a reference to the
NotificationsManager
object in memory. By default, this variable is assigned and null. We should
assign this variable a value directly from the Unity Object Inspector. To do this, simply drag and drop
the
Camera
object (or
Empty
object), with the
NotificationsManager
component attached, from the
Hierarchy panel and into the
Notifications
slot in the Object Inspector, when the
obj_Poster
object
is selected. This completes the assignment (see Figure
3-11
). Notice that Unity is smart enough
to detect which component on the source GameObject should be assigned to the
Notifications
variable in the Object Inspector.
Figure 3-11.
Assigning the NotificationsManager instance to the Notifications variable of class Poster, using the Object Inspector
Note
For more information on the Unity
Input
class, see the online documentation at
We'll also need to create an additional script for the
Listener
object, which should register with the
NotificationsManager for keyboard events, and then respond to them when they occur. The Listener
script can be seen in Listing 3-15.
Listing 3-15. Responding to Keyboard Events with a Listener (Listener.cs)
01 using UnityEngine;
02 using System.Collections;
03
04 public class Listener : MonoBehaviour
05 {
06 //Reference to gloabl Notifications Manager
07
public NotificationsManager Notifications = null;
08