Greetings!
I am trying to fix the position of objects inside a UIGrid.
Right now I have a deck object in top corner. When I add cards to it, I want to offset those cards by width/2 and height/2 so they are top left added to the list (instead of center added as they are currently):
However when I offset the position of the children when I add them, I think those changes get overriden by having to call Reposition() (and nothing appears if I don't call that).
Here is my code:
//Puts cards at the top of the screen
public static void dealFirstHand()
{
deck = GameObject.FindGameObjectWithTag("deck");
for(int i =0;i<6;i++)
{
GameObject card = NGUITools.AddChild(deck,Resources.Load("Prefabs/UI/CardSlot") as GameObject);
assignRandomCard(card.GetComponent<UI_Controller_CardSlot>().cardArt);
UIPanel display = card.transform.GetComponentInChildren<UIPanel>();
card.transform.parent = deck.transform;
card
.transform.localScale = new Vector3
(1f,1f,1f
); card
.transform.position = new Vector3
(display
.width/2,display
.height/2,
0); playerCards.Add(card.GetComponent<UI_Controller_CardSlot>().cardArt,false);
card.GetComponent<UI_Controller_CardSlot>().cardArt.activate();
}
deck.GetComponent<UIGrid>().Reposition();
}
Can you advise how I can properly get it so cards are added so that my offset values apply? I verified card.transform.position = new Vector3(display.width/2,display.height/2,0); gives the correct values so can you tell me where I can put this to get it to register? Do I need to loop through the cards again and reposition them manually? (That seems very inefficient)
The object being added is center pivoted, and I want that to stay center pivtoted. I just want the children added to be offset by width/2 and height/2.
Thanks