Add this to any game object across all scenes
Example usage
public void Start()
{
EventManager.instance.AddListener("sayHello", OnSayHello);
}
public void OnSayHello()
{
Debug.Log("Hello!");
}
And then inside of any other script you can trigger the event which will invoke all the registered callbacks
EventManager.instance.Trigger("sayHello");
You can also pass an argument to the callback:
public void Start()
{
EventManager.instance.AddListener("sayThing", OnSayThing);
}
public void OnSayThing(dynamic thingToSay)
{
Debug.Log(thingToSay.toString());
}
When you trigger the event, make sure you pass the argument
EventManager.instance.Trigger("sayThing", "Hello world!");