Game Development Reference
In-Depth Information
}
void OnDisble ()
{
RocksTrigger.onTrigger -= OnTrigger;
}
void OnTrigger ()
{
EnabledRigidbody();
}
We used the OnEnable() function to add a function that will be called when the event
is triggered. We use the OnDisable() function to remove a function when the game
object is inactive. Then, the OnTrigger() function is the function that will be called
when the event is triggered, which we call the EnabledRigidbody() function, to
make the rock slide.
Tip
The delegate and event methods are better than the BroadcastMessage method
that we've used in Project 5 , Build a Rocket Launcher! , because we don't have to set up
the listener as a child of the event trigger. Also, the BroadcastMessage method is
slower than the delegate and event methods because it needs to iterate to all the chil-
dren in this game object to be able to call the function.
Search WWH ::




Custom Search