Game Development Reference
In-Depth Information
With that in mind, let's edit the
MyAlarmScannerModule
script and add a new public
property for the
Alarms
as follows:
public GameObject[] Alarms;
Then replace the boiler plate line
TriggeredCameraLocation = Vector3.zero;
with the following:
TriggeredCameraLocation = Vector3.zero;
foreach (var alarm in Alarms)
{
if (!alarm.activeSelf)
{
TriggeredCameraLocation = alarm.transform.position;
}
}
This simply loops the alarms and if it finds one that is inactive, it sets the
TriggeredCameraLocation
to the position of the triggered alarm; this will
then cause all the selected
Droids
to be activated.
With everything set, all that remains is to create an
EventSystem
in the scene
(
Create
|
UI
|
EventSystem
), add the
MyAlarmScannerModule
script to the
EventSystem
, then add all the Pickups to the
Target Droids
array property
and all the
Alarms
to the
Alarms array
property.
Note: We only add an
EventSystem
to the scene for the custom input
module. We don't actually need a
Canvas
or any UI components!
If everything went well, when you run the scene and move the sphere using
the arrow keys, when the Hero accidentally trips one of the alarms, they will be
assaulted from all sides by the cubes.