Question by
Malleck666 · Jul 14, 2016 at 10:55 PM ·
c#scripting problemtransform
Transform along X increases for seemingly no reason...
I have a method as follows which updates the view of a player's hand with gameobjects to represent the cards in their hand.
public void UpdateHand()
{
foreach(Transform t in handZone.GetComponentInChildren<Transform>())
{
Destroy(t.gameObject);
}
foreach (Card c in player1Hand)
{
GameObject cardPrefab = Instantiate(handCardPrefab) as GameObject;
cardPrefab.GetComponentInChildren<HandCard>().cardFace = c.image;
cardPrefab.transform.SetParent(handZone.transform);
}
float posXSpace = (handAreaSize / player1Hand.Count);
float posX = 0;
foreach(Transform o in handZone.GetComponentInChildren<Transform>())
{
o.transform.localPosition = new Vector2(posX, 0f);
posX += posXSpace;
}
}
For some reason, each time it is called, the whole lot shifts far along the X axis across the screen. Maybe I'm missing something simple but can anyone see the error?
Thanks in advance.
Comment
Your answer
Follow this Question
Related Questions
Vector3.Lerp not working properly, making the player bounce around 2 Answers
A way to make the player get punished when standing still? 0 Answers
Randomly set an integer as positive or negative? 1 Answer
How to change rotation for a FirstPersonController through script. 0 Answers
+= operator on transform.localPosition results in random values 1 Answer