This is an example of a Poster class and a Listener class using the Delegates EventManager class created previously.
using UnityEngine;using System.Collections;public class Poster : MonoBehaviour { //C# accessors for private variable public int Health { get { return _health; } set { //Clamp health between 0-100 _health = Mathf.Clamp(value, 0, 100); //Post notification - health has been changed EventManager.Instance.PostNotification(EVENT_TYPE.HEALTH_CHANGE, this, _health); } } //Internal variables for health private int _health = 100; void Start() { StartCoroutine("DamageHealth"); } IEnumerator DamageHealth() { while (Health > 0) { yield return new WaitForSeconds(1f); Health -= 5; } }}using UnityEngine;using System.Collections;public class Listener : MonoBehaviour { // Use this for initialization void Start() { //Add myself as listener for health changes event EventManager.Instance.AddListener(EVENT_TYPE.HEALTH_CHANGE, OnEvent); } //Called when events happen public void OnEvent(EVENT_TYPE Event_Type, Component Sender, object Param = null) { //Detect event type switch (Event_Type) { case EVENT_TYPE.HEALTH_CHANGE: OnHealthChange((int)Param); break; } } //Function called when health changes void OnHealthChange(int NewHealth) { Debug.Log("Health: " + NewHealth.ToString()); }}