Game Development Reference
In-Depth Information
onTrigger();
}
}
}
Here, we've used the
delegate
and
event
methods (available only in C#),
which basically call the
onTrigger()
function on any object that has the event
listener. However, in JavaScript, we don't have the
delegate
and
event
meth-
ods, so we use the custom class called
JSDelegate
, which is already present in
with the project's package. We can go to the
Chapter7/Scripts/Javas-
cript/Utils
folder in the
Project
view and open
JSDelegate
to check out
this class. We will get more details on this in the
Classified intel
section.
3. We already have the
trigger
script. Next, we need the
listener
script to
listen to the trigger and make the rocks fall down. We will create a new script by
going to the
Scripts
folder in the
Project
view to create a script by right-click-
ing and navigating to
Create
|
C#
(for C# users) or
Create
|
Javascript
(for
JavaScript user) and rename it
Rocks
.
4. Double-click on the
Rocks
script to open it in MonoDevelop and start adding the
script as follows:
// Unity JavaScript user:
#pragma strict
@Range(-100, 0)
var downForce : int = -80;
private var _rigidbodys : Rigidbody[];
function OnEnable () : void
{
RocksTrigger.onTrigger.Add(OnTrigger);
}
function OnDisble () : void
{
RocksTrigger.onTrigger.Remove(OnTrigger);
}
function OnTrigger () : void