Quantcast
Channel: Unity Forum
Viewing all articles
Browse latest Browse all 1466670

[C#] Working with AddListener

$
0
0
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:

Code (CSharp):
  1. // ADD LISTENER SO IT REACT TO CLICKS
  2.             newItem.GetComponent<Button>().onClick.AddListener(() =>
  3.                                         {print ("GET: " + newItem.GetComponentInChildren<Text>().text);});
But not this:

Code (CSharp):
  1. // ADD LISTENER SO IT REACT TO CLICKS...
[C#] Working with AddListener

Viewing all articles
Browse latest Browse all 1466670

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>