row = 0; counter = -1;
if (ASuitedCardsList.Count > 0) {
for(int i = 0; i < 1; i++) {
for(int j = 0; j < totalSuitedA; j++){
counter++;
Debug.Log ("8" + j);
ASuitedCardsList[counter].GetComponent<RectTransform>().anchoredPosition3D = new Vector3(640 + row * 30, 170 + j * -30,6);
ASuitedCardsList[counter].SetActive(true);
}}}
First time I display these buttons they are in the right place.
Second time I loop over the above code the buttons seem to start off at the position the last button was created even though the Vector3 position is exactly the same.
Am I correct in saying that the anchoredposition starts where the last anchoredposition was set?
What do I need to do so that the buttons don’t move when displayed for the second time?
For information:
Originally the gameObjects that I get to display in the above code are initialised by the following code:
trans = go1.GetComponent<RectTransform>();
go1.transform.SetParent (GameObject.FindObjectOfType<Canvas> ().gameObject.transform, false);
trans.anchorMax = new Vector2(0,1);
trans.anchorMin = new Vector2(0,1);
RectTransformExtensions.SetPositionOfPivot(trans, new Vector2( 0.5f, 0.5f));
RectTransformExtensions.SetHeight(trans, 30);
RectTransformExtensions.SetWidth(trans, 30);
go1.GetComponent<RectTransform>().anchoredPosition = new Vector3(x2 + 20, y - 60, 6);