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 - build the deck

The strategy we'll use to build our deck is to create an array of possibilities, randomly choose one of those possibilities, and then remove that possibility as an option. Let's see how that works.

  1. In the BuildDeck function, start off by declaring a few variables:
    function BuildDeck()
    {
    var totalRobots:int = 4; // we've got four robots to work with
    var card:Object; // this stores a reference to a card
    }
    
  2. Next, build a loop to step through each of the four colored robot types:
    for(i=0; i<totalRobots; i++)
    {
    }
    

    That loop will run four times because totalRobots is set to 4. Next, create an array called RobotParts that will house the names of the body parts we can knock off:

    for(i=0; i<totalRobots; i++) { var aRobotParts:Array ...

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