This is a tutorial about C# events and delegates and how to use these for game programming in Unity 5 game engine.
Events are a method to notify other scripts in Unity about a change, e.g. a state of a GameObject. In the tutorial there is a player with a simple healthpoint-system implemented. The healthpoints are decreased continuously and on each decrease an event called HealthUpdate is raised. Another script that is attached to an UI GameObject for displaying the healthpoints binds the event and updates it’s UI in an event handler.
In the tutorials you learn how to:
- Define events and event handlers
- Bind the events in a separate script and GameObject
The events are defined with the static operator, this means that you don’t need to create an instance of your class to bind the events. In a next tutorial I will explain how you can bind the events for a special instance of your class and how you can make use of singletons as a global component in your game that raises events.by