- Home /
Set GameObject for OnClick.AddListener Lambda
New to Unity UI and trying to find a way to tell the listener which specific GameObject to use when the OnClick event is triggered. My code works but I have no control over which Canvas is used. Let me know if anyone has insight, thanks.
Example Code: newButton.onClick.AddListener(() => {Method();}); Below is how this would be set in the Editor rather than what I'm trying to do Programmatically.
screen-shot-2017-04-18-at-64253-pm.png
(16.3 kB)
Comment
Dont use lamda , create a class and method FE: public void Click() { ... }
then attach this class on the button game object and put the button game object into your field in screen, next select from right drop down your method name (Click())