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 - 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.

  1. 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;
    
  2. Look a little further down the code. Pass the id value to the Card 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++;
    
  3. Add id as a property of the Card class. Accept id as an argument in the Card class constructor function, ...

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