So I was making my inventory. And I want the user to be able to move items. I have a 4x6 grid of buttons all assigned in a table:
PhysGUI = InvPanel.GetComponentsInChildren<Text> ();
That’s fine, when I try to add listeners to them, all of them give me 24. The assignment is in a for loop:
for (int i = 0; i < PhysGUI.Length; i++) {
Debug.Log (i.ToString ());
PhysGUI*.gameObject.GetComponentInParent<Button> ().onClick.AddListener (delegate {*
-
ButtonPress (i);* -
});* -
}*
ButtonPress() prints out the number that comes up immedeately, and no matter which button I push, I get 24.
Is there something I’m missing? Or what?