Time for action – building the card-flipping function

The game will let the player flip over two cards. Then, it will pause for a brief moment and flip the cards back over. We'll worry about detecting matches for our grand finale in just a moment.

  1. Add the following code to your FlipCardFaceUp function:
       function FlipCardFaceUp(card:Card)
       {
         card.isFaceUp = true;
         aCardsFlipped.Add(card);
       
         if(aCardsFlipped.Count == 2)
         {
           playerCanClick = false;
                
           yield WaitForSeconds(1);
                
           aCardsFlipped[0].isFaceUp = false;
           aCardsFlipped[1].isFaceUp = false;
       
           aCardsFlipped = new List.<Card>();
             
           playerCanClick = true;
          }
       }
  2. Then, make a small change to one line in the BuildGrid function:
       if(GUILayout.Button(Resources.Load(img),
         GUILayout.Width(cardW)))
       {
     if(playerCanClick) ...

Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.