So I am trying to empty a card pile and I iterate over the children of the pile game object but only some of them are affected (maybe some are only children in the hierarchy?).
This is the code:
public void TransferCardsTo(PlayerManager player)
{
FlipCards(pile);
player.deck.AddRange(pile);
pile.RemoveRange(0, pile.Count);
foreach (Transform child in this.transform) // moving the cards from the pile to the player's deck
{
Debug.Log(child.transform);
child.transform.SetParent(player.transform,false);
}
}
And I have only one draw function so I couldn’t figure out what can diffrentiate between these objects.
public CardClass PullCard()
{
GameObject card = deck[0];
card.transform.SetParent(cardPile.transform,false);
card.transform.position = cardPile.transform.position;
card.GetComponent<CardFlipper>().Flip();
cardPile.GetComponent<Pile>().AddCard(deck[0]);
deck.Remove(deck[0]);
return card.GetComponent<CardClass>();
}
Anyone knows what is the problem?
In the hierarchy, some of the cards game objects stay as children of the pile game object and some does not.