Join Kelley Hecker for an in-depth discussion in this video Other MonoBehaviour event receivers, part of Unity: Scripting with C#.
- If we look back at the MonoBehavioural…life cycle graph, we can see that there…are many events that are sent to MonoBehaviours…besides Awake, Start, and Update.…I'll go over a few of the ones you're most likely to use.…OnEnable and OnDisable are called when the script…is enabled or disabled.…Disabling a script only stops the Awake, Start,…and Update functions from being called.…So if you have InvokeRepeating or coroutines running…you may want to stop them in OnDisable…and restart them on OnEnable.…
OnCollisionEnter, OnCollisionStay, and OnCollisionExit…are called when a rigid body collides with something.…This event passes the colliding object as an argument.…OnTriggerEnter, OnTriggerStay, and OnTriggerExit…are essentially the same as OnCollision events…except that they work for triggers instead of colliders.…A trigger isn't affected by the physics system…and is used for things like determining…when an object enters an area.…Colliders that enter a trigger will pass right through.…While you'll use Update most of the time,…
- Defining classes and variables
- Attaching scripts to objects
- Understanding MonoBehaviour class
- Using the Unity Scripting API
- Importing assets
- Using a singleton pattern to manage game state
- Creating an event
Skill Level Intermediate
Q: Why am I getting a script compile error when trying to load the exercise files?
A: This course was recorded in Unity 4.6, and Unity has since released Unity 5. There are two items to address for Unity 5 users.
Q: Why can't I see the Render Settings option in the Edit menu?
A: The Render Settings options have been moved in Unity 5. You can access them by going to the Window menu and choosing Lighting. In the window that loads, Render Settings can be found under the Scene tab.