slowing Game to see AI card play

HI I am creating a 2D card playing card game in Unity. The game is a two player game. I am using the update method with a Finite State Machine to change states of the game in a Game Manager script. When playing the game if I play first the AI(computer Opponent) plays so fast his card doesn’t appear in the played cards area but in the leaf for the winner of that leaf. I have search the net and tried coroutines, Timers etc. but hasn’t bean able to pause so that the AI card appears in the played cards area before going to the winning player leaf.

What is the best approach to slowing down the play of the AI so his cards can be seen on the board?

A coroutine does not experience Update the same way MoboBehaviours does.

float timer = 0f;
while (timer < 3000f) {
    timer += 0.02;
}

The snippet above will quite frankly obviously be finished instantly, and from the perspective of the coroutine, that is what it looks like.

Another thing that is important to understand about coroutines is that they are not synchronous - meaning the rest of your script will not wait for the coroutine to finish before it proceeds. The function starting the coroutine should naturally end right after calling it. Furthermore, it’s the logic in your Update function that will resume, which will automatically happen once the coroutine changes the value of the gameState variable.

Your coroutine should look more like this:

public IEnumerator Pause() {
    gameState = GameState.Waiting; // I'm assuming this gameState means nothing will happen.
    // If not then you should make a new GameState Pause, that will just do nothing.
    yield return new WaitForSeconds(3f);
    gameState = GameState.Playing; // Continue where you left off. I don't know your program,
    // so it might not be GameState.Playing, but by changing gameState you will change what the 
    // update function does from now on.
}

and the coroutine should be started right after the AI has done the move that you want to display.

This is my Update method

private void Update()
	{		
		switch (gameState)
		{
			case GameState.SettingUp:
				SettingUp();
				break;
			case GameState.Begging:
				Begging();
				break;
			case GameState.Waiting:
				Waiting();
				break;
			case GameState.Playing:
				Playing();
				break;			
			case GameState.Scoring:
				Scoring();
				break;			
		}
	}

here is my coroutine

IEnumerator Pause()
	{
		float timer = 0;
		
		while(timer < 3000f)
		{
			timer += Time.time * Time.deltaTime;
		}
		//gameState = GameState.Playing;

		yield return new WaitForSeconds(5);
		
	}

I call it from my playing method but everything happens so fast I cant see the AI card when it is played

public void Playing()
	{
		StartCoroutine("Pause");

		if (isPlayer1Turn && gameState == GameState.Playing)
		{
			List<Card> pHand = player1.GetComponent<Player>().GetHand();        // Get player1 hand

			//List<Card> trumpCards = pHand.FindAll(x => x.GetCardSuit() == trump.GetCardSuit()); // Get all the trumps cards in his hand.
			// if player1 hand is null return
			if (pHand == null)
			{
				return;
			}

			// if player hand has cards
			if (pHand.Count > 0)
			{
				// if there areno playedcards
				if (playedCards.Count == 0)
				{
					int pos = Random.Range(0, pHand.Count);             // create a random integer for the card to get
					Card card = pHand[pos];                             // assign that card to a new card object
					pHand.RemoveAt(pos);                                // remove the card from the player hand
					card.transform.SetParent(playedCardsGO.transform);  // Set the card parent
					card.transform.position = new Vector3(1f, 1f);      //set the card position
					card.GetComponent<Card>().ToggleFace(true);
					playedCards.Add(card);                              // add the card to the playedCards List
					infoText.text = player1.GetComponent<Player>().playerName + "played";     // Set the inforamtion text 

					gameDeck.ResetGameObjects(player1);                                         // Reset player1 children
					gameState = GameState.Waiting;                      // Change the gameState to waiting
					isPlayer1Turn = false;                              // change the player turn
				}
				// if the played cards is 1
				else if (playedCards.Count == 1)
				{

					Card playedCard = playedCards[0];           // get the played card
					List<Card> cardMatches = pHand.FindAll(x => x.GetCardSuit() == playedCard.GetCardSuit());  // check the player hand to see if he has same suit

					// if there are matches
					if (cardMatches.Count > 0)
					{
						//Card match =cardMatches.Find(x=>(int)x.GetCardValue() > (int)playedCard.GetCardValue());
						int val = cardMatches.Max(x => (int)x.GetCardValue());              // create an int varibale to get the max value of the matches
						Card card = cardMatches.Find(x => (int)x.GetCardValue() == val);    // Find themax value and assign that card to a new card

						//if the card has a greater value that the other  card played
						if ((int)card.GetCardValue() > (int)playedCard.GetCardValue())      // 
						{
							playedCards.Add(card);                                  // add the card to played cards
							pHand.Remove(card);                                     // remove the card from the had
							card.transform.SetParent(playedCardsGO.transform);      // Set the parent of the card
							card.transform.position = new Vector3(9f, 3f);          // Set the new position of the card
							card.GetComponent<Card>().ToggleFace(true);
							
							CheckTrick(playedCards, 1);                             // Check to see who wins the trick

						}
						// if the card is less
						else
						{
							playedCards.Add(card);                                  // add the card to played cards
							pHand.Remove(card);                                     // remove the card from the had
							card.transform.SetParent(playedCardsGO.transform);      // Set the parent of the card
							card.transform.position = new Vector3(9f, -3.2f);       // Set the new position of the card

							//seconds = 0;
							//gameState = GameState.Pause;

							CheckTrick(playedCards, 1);                             // Check to see who wins the trick

						}
					}
					else
					{
						int rand = Random.Range(0, pHand.Count);
						Card card = pHand[rand];

						playedCards.Add(card);                                  // add the card to played cards
						pHand.Remove(card);                                     // remove the card from the had
						card.transform.SetParent(playedCardsGO.transform);      // Set the parent of the card
						card.transform.position = new Vector3(9f, -3.2f);       // Set the new position of the card
						
						CheckTrick(playedCards, 1);                             // Check to see who wins the trick	
					}
				}
			}
			//StopCoroutine("Pause");
		}
	}

Can you give some guidelines as to how I can go about doig this coroutine? So it delays the AI before it plays and after it plays so the card can be seen before it goes to the player leaf.

@LeanardNS