Hi, I just had a weird issue in a small code.
I have a list of 9 CollumnButtons, that need a function on click, PlaceStone(int).
When I assign the function like this:
for(int i = 0; i < ColumnButtons.Count; i++) {
ColumnButtons*.onClick.AddListener(delegate { PlaceStone(i); });*
}
The PlaceStone function get 9 as the int input.
But if i do this:
for(int i = 0; i < ColumnButtons.Count; i++) {
int num = i;
ColumnButtons[num].onClick.AddListener(delegate { PlaceStone(num); });
}
Everything work correctly, PlaceStone() get 0 to 8 as the int input.
Any idea why?