I have been searching for the answer but not been able to find it so i ask here.
Could someone please explain to me why this works:
// ADD LISTENER SO IT REACT TO CLICKS
newItem.GetComponent<Button>().onClick.AddListener(() =>
{print ("GET: " + newItem.GetComponentInChildren<Text>().text);});
But not this:
// ADD LISTENER SO IT REACT TO CLICKS
newItem.GetComponent<Button>().onClick.AddListener(() => {DoThis();});
===
void DoThis() {
print ("GET: " + newItem.GetComponentInChildren<Text>().text);
}
Typically there is no need to remove a listener, it will be cleaned up automatically when the button is destroyed. Unless of course you want to change the listener.