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 - store the essentials

There are a few crucial values we need to remember throughout our game. Let's declare some variables at the very top of the GameScript (remember that typing the comments is optional, but the comments may help you understand the code).

var cols:int = 4; // the number of columns in the card grid var rows:int = 4; // the number of rows in the card grid var totalCards:int = cols*rows; // I think the answer is 16, but I was never good with numbers. var matchesNeededToWin:int = totalCards * 0.5; // If there are 16 cards, the player needs to find 8 matches to clear the board var matchesMade:int = 0; // At the outset, the player has not made any matches var cardW:int = 100; // Each card's width and height is 100 ...

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