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.
Create a new function called
FlipCardFaceUp
. As you did with theBuildDeck
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() { }
Call the
FlipCardFaceUp
function from inside the card creation code:if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW))) { FlipCardFaceUp(); Debug.Log(card.img); }
We need to tell the
FlipCardFaceUp
function which card has been flipped. Modify the line to pass a reference to the clicked-on card as an argument:FlipCardFaceUp(card);
Now, we need to accept that card as an argument in our...