Game Development Reference
In-Depth Information
Make sure you have also added the AlarmSystem and
MyAlarmScannerModule scripts from the previous section to complete
this example.
In this example, we will add four alarm plates, which when triggered will cause all
the enemy spinning blocks to charge in to attack the hero. (However, since the ball
just collects the cubes, it really ends up more like Mario with a Coin hoover.)
To implement our fancy new custom event, we need a couple of things, namely:
• A script that implements our new event interface
• A script for the Alarm trigger that our Custom Input System will be
watching out for
• Some logic in our Custom Input system to watch for triggered alarms
(we just have boilerplate at the moment that does nothing)
All of this is very simple and basic.
This example has been greatly simplified in order to it it within the
scope of this title (else it could have been at least twice as big). I'll
probably do a much larger example using these techniques on my blog
at a later date (if I haven't yet when you're reading this). Keep an eye on
the forums where it will be announced.
The Droid script
The script for our alert sentries, who are waiting for some kind of alarm to strike
them into action is very easy to implement (especially if you have been following
along). It is in effect no different to building a script that implements the built-in
UI events.
First, create a new C# script called DroidScript (either in the Project script folder or
in the Roll a Ball script folder) and either add the IAlarmHandler interface manually
to implement that interface (using the handy trick I showed you earlier) or just
replace its contents with the following:
using System.Collections;
using UnityEngine;
 
Search WWH ::




Custom Search