Alright, my logic is all wrapped up in it self and I am hoping for some help.
I am generating a grid, 4X4, and trying to assigning each button to its own OnClick().
My apparent problem is that when it assigns the OnClick() to my CardClicked(k,l);, it sends it in the variable state. Meaning that when I build my deck with k and l, all of the OnClicks() are assigned to the very last card because the value of k and l will always be those numbers.
Can I loop assign OnClick()s in a way where they stay what they are when being assigned using variables?.
I am also willing to accept the fact thatI may be going about this all wrong, I am create a memory card game using the GUI, it is the example in the book i am learning from, however it was published prior to 4.6 and I am trying to accomplish the same task but with uGUI and it is a bit more of a challenge it seems. Not that I don’t like a challenge, it has helped me learn a great deal about Unity. Just keep hitting snags.
for(var k:int =0; k<rows;k++)
{
cardBack=backPanel.transform.GetChild(k);
cardFace=facePanel.transform.GetChild(k); //first child of canvas
//First row of Canvas
for(var l:int=0; l<cols; l++)
{
cardButtonBack=cardBack.transform.GetChild(l);
cardButtonFace=cardFace.transform.GetChild(l);
cardButtonFace.GetComponent(UnityEngine.UI.Image).sprite=aGrid[k,l].pic;
//Rename button so that it has grid coordinates in it and can be referenced by treating the
//String as an array and reading [6] for x and [7] for y!!
cardButtonFace.name=cardButtonFace.name + k + l;
cardButtonBack.name=cardButtonBack.name + k + l;
buttonBuilder=cardButtonBack.GetComponent(Button);
buttonBuilder.onClick.AddListener(function()
{
CardClicked(k,l);
Debug.Log(cardButtonBack.GetComponent(Button));
});
}
}