Time for action - build 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.
- 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 ArrayList(); playerCanClick = true; } }
- Then, make a small change to one line in the
BuildGrid
function:if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW))) { if(playerCanClick) { FlipCardFaceUp(card); ...
Get Unity 3D Game Development by Example 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.