I am adding a list of buttons in code for which I would like to add a click listener.
I am able to add the listener, the issue is I would like to know the button that called the listener.
I have tried the following method, but the passed value to the listener is always the same:
foreach (...)
{
    var button = (Button)GameObject.Instantiate(...);
    packIndex++;
    button.onClick.AddListener(() => this.OnButtonClick(packIndex));
}
public void OnButtonClick(int idx)
{
    // idx is always the latest value in the above loop
}
TL;DR
How do you find the caller from a button click listener?
 
     
     
    