Game Development Reference
In-Depth Information
}
}
}
In the preceding function, we create the event listener and then apply a down
force to make the rock fall down faster by using the OnEnable() and OnDis-
able() functions to add and remove the event listener. OnEnable() gets
called every time the game object is enabled or active. On the other hand,
OnDisable() will be called every time the game object is disabled or inactive.
Tip
We also use the [Range(Min,Max)] function in C# or @Range(Min,Max)
followed by the int , float , or double variables to create the limit-value
slider in the editor.
This is a very convenient way to create the slider without creating a custom in-
spector as we did in Project 6 , Make AI Appear Smart . We can see the result in
the following screenshot:
5. Now we are finished with the script. We will go back to Unity, go to the Hier-
archy view, and click on the TriggerArea game object. Then, we will drag the
RocksTrigger script on this game object, as shown in the following screenshot:
Search WWH ::




Custom Search