Last active
March 11, 2024 00:02
-
-
Save rutcreate/3e6ae2f39cbe2a41d84a to your computer and use it in GitHub Desktop.
Unity3D: Best way to add listener programmatically for Button onClick
Thank you very mucjh öperi,m geri kaç
I was trying to do this for an hour and the solutions I found before this were innecessary complex. Thank you! This worked fine for me!
that' s so useful 👍
Thanks :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
should be like:
var i2 = i;
button.onClick.AddListener(() => OnClick(i2));
source: https://docs.microsoft.com/tr-tr/archive/blogs/ericlippert/closing-over-the-loop-variable-considered-harmful