I would like to subscribe to an event so that when the event fires I can execute a delegate or anonymous function.
Subscribing to events with methods is easy I can just type the method name, this works fine:
UnityEngine.UI.Toggle tgl;
tgl.onValueChanged += myMethod;
But I cannot subscribe a delegate using the same syntax. This will not work:
tgl.onValueChanged += delegate{ Debug.Log("Bang!"); };
I researched this Q&A which suggested I try the following approach but this is also not working:
tgl.onValueChanged += (object sender, EventArgs e) => { Debug.Log("Bang!"); };
How can I make this work?