I’m making a simple playing card game and I want to start the game by dividing a 52 card deck into two smaller decks. When I try to use a coroutine to animate the cards into position they all get added instantly.
//Splits a deck into smaller decks
IEnumerator DivideDeck(Deck d, int pNum)
{
//Alternate between the number of players
int count = 0;
//Animate the cards to the new deck positions
for(int i = 0; i < d.cards.Count; i++)
{
Card c = d.cards*;//Get the card*
-
//If no cards are moving, then move this card to the player deck*
-
c.StartCoroutine(c.MoveToPosition(playerDecks[count].transform.position));//start moving the deck*
-
while(cardsInMotion)//If the cards are moving don't physically place them in the deck until after they've animated into position*
-
yield return new WaitForSeconds(.1f);*
-
playerDecks[count].AddCard(c, 0);//physically place the card in the deck*
-
count++;*
-
if(count == pNum)*
-
count = 0;//reset the count*
-
}*
-
}*
Outside of this coroutine is a RepeatInvoking() that constantly checks if there are any cards in motion. And it is called OnAwake(). However the while loop that checks to see if the cards are moving isn’t triggering and the cards get teleported instantly instead of animated. I’m not really sure how to properly do this so that it first animates the cards over, then triggers the lines after the while loop.
Thanks for your help!