I have a ScrollView with a Grid Layout Group component on the Content object :
My item list is inside the Content object and each item own a Button component.
I'm trying to add the onClick programmatically to handle a lot of objects and index with a parameter like this :
int i = 0;
foreach(Button btn in scrollViewContent.GetComponentsInChildren<Button>()) {
btn.onClick.AddListener(() => Load(i));
i++;
}
However onClick I always get the last index + 1 on all item click. Here are my logs :
Until Log 44, this is the foreach print loop and the Log "index : 45" is the result on click.
So two question :
• Why all item click return the same index ?
• How can I get index 45 whereas the i var stopped at 44 ?

