Time for action – building the card-flipping function

This card-flipping code looks pretty good, but there's no way to test it without adding some way of flagging that isFaceUp variable to true. Let's build a new function to do just that, and call it whenever a card button is clicked.

  1. Create a new function called FlipCardFaceUp. As you did with the BuildDeck function earlier, write this function outside of and apart from your other functions—make sure it's not trapped inside the curly brackets of one of your other functions.
       function FlipCardFaceUp()
       {
          
       }
    
  2. Call the FlipCardFaceUp function from inside the card creation code:
       if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
       {
       
       FlipCardFaceUp();
          Debug.Log(card.img);
       }

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.