O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - build 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);
    }
    
  3. We need to tell ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required