Hey there,
I’m having a problem with transform child, when this program runs it currently doesn’t correctly delete the elements in the deck list and adds the incorrect elements into the discard pile list. I’m certain that child.childCount is not correct for finding the correct child at its index in the list which is why the deck and discard pile lists are not working as intended.
Basically what is supposed to happen is that the elements from the list of deck are supposed to go into discard pile and then reset when there are no more elements left in deck.
public void DealFromDeck()
{
//add remaining cards to discard pile
foreach (Transform child in deckButton.transform)
{
if (child.CompareTag("Card"))
{
deck.Remove(child.childCount);
discardPile.Add(child.childCount);
Destroy(child.gameObject);
}
}
if (deckLocation < draw)
{
//draw card
drawOnDisplay.Clear();
float xOffset = 2.0f;
foreach (int card in deckDraw[deckLocation])
{
GameObject newTopCard = Instantiate(cardFaces[card], new Vector3(deckButton.transform.position.x + xOffset, deckButton.transform.position.y, deckButton.transform.position.z), Quaternion.Euler(0, 0, Random.Range(0.0F, 1.0F) < 0.5F ? 0.0F : -180.0F), deckButton.transform);
GameObject artAnimation = Instantiate(cardContainer, new Vector3(deckButton.transform.position.x + xOffset, deckButton.transform.position.y, deckButton.transform.position.z), Quaternion.Euler(0, 0, Random.Range(0.0F, 1.0F) < 0.5F ? 0.0F : -180.0F), deckButton.transform);
artAnimation.transform.parent = newTopCard.transform;
drawOnDisplay.Add(card);
xOffset = xOffset + 1.5f;
}
deckLocation++;
}
else
{
//restack the top deck
RestackTopDeck();
}
}
void RestackTopDeck()
{
foreach (int card in discardPile)
{
deck.Add(card);
}
discardPile.Clear();
SortDeck();
}