VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/events-and-delegates-in-unity/

⇱ Events and Delegates In Unity - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Events and Delegates In Unity

Last Updated : 4 May, 2026

A delegate is a variable that holds a reference to a method. An event uses delegates to notify multiple scripts when something happens.

  • One script announces an event
  • Other scripts listen and respond
  • The sender doesn't need to know the receivers

Events and delegates in Unity are used to enable communication between different scripts in a flexible and decoupled way. 

Need of Events

Without events:

With events:

The coin doesn't need to know who is listening. You can add or remove listeners without changing the coin script.

Creating an Event

This script fires an event when player touches the coin. Any script listening will respond.

OnCoinCollected?.Invoke() calls all listening methods. The ? checks if any listeners exist.

Listening to Events

This script subscribes to the coin event and adds score when coin is collected.

+= subscribes to event. -= unsubscribes - important to prevent memory leaks.

Passing Data with Events

Sometimes you need to pass data like score value or damage amount.

Example: Enemy

ScoreManager:

Complete Example: Health Events

Health script fires events when health changes or player dies.

Example: Health

UI script listens and updates health bar.

UnityEvent

UnityEvent can be assigned in Inspector without writing code.

In Inspector, you can drag GameObjects and select methods to call.

Comment
Article Tags:
Article Tags:

Explore