Join Kelley Hecker for an in-depth discussion in this video What is an event?, part of Scripting Unity with C#.
- Let's talk about events.…The events system in C# is another way…to send messages between objects.…An event is a message sent from one object to another,…usually to signal that a certain action has occurred.…For example, a mouse button has been pressed…or the player has died.…The big difference between send a message…and an event is that with send message,…you must have a reference to the game object…you're sending the message to.…When sending an event, the sender has no information…about the objects receiving the event.…
This is good because it keeps your code more modular…and reusable.…Objects can register for events…and decide which function will be called…when the event occurs without the sender…having to do anything or know anything about the object.…Because the sender doesn't know…which function will be called when an event is sent,…we use a special type of object called the delegate.…The delegate holds a reference to the function…and defines its signature.…While events and delegates might sound complicated,…
- 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.