Time for action – ID the cards
Let's revisit our card-creation code and give each card an ID number. We'll use that number to detect matches.
- In the
BuildDeck
function, add this line:function BuildDeck() { var totalRobots:int = 4; // we've got four robots to work with var card:Object; // this stores a reference to a card var id:int = 0;
- Look a little further down the code. Pass the
id
value to theCard
class with each robot and missing body part card, and then increment the ID number:card = new Card("robot" + (i+1) + "Missing" + theMissingPart, id); aCards.Add(card); card= new Card("robot" + (i+1) + theMissingPart, id); aCards.Add(card); id++;
- Add
id
as a property of theCard
class. Acceptid
as an argument in theCard
class constructor function, ...
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.