Skip to content

Instantly share code, notes, and snippets.

@Problematic
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Problematic/31007b5955a1683dd0d3 to your computer and use it in GitHub Desktop.
Save Problematic/31007b5955a1683dd0d3 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class EventConsumer : MonoBehaviour
{
EventProvider ep;
void Awake ()
{
ep = GetComponent<EventProvider>();
}
void OnEnable ()
{
ep.OnSomeEvent += HandleOnSomeEvent;
}
void OnDisable ()
{
// Remove our event handler when we're
// disabled to prevent handling the same
// event multiple times
ep.OnSomeEvent -= HandleOnSomeEvent;
}
void HandleOnSomeEvent ()
{
Debug.Log("SomeEvent handled!");
}
}
using UnityEngine;
using System.Collections;
public class EventProvider : MonoBehaviour
{
public delegate void SomeEvent();
public event SomeEvent OnSomeEvent;
void Update ()
{
if (OnSomeEvent != null)
{
OnSomeEvent();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment