Time for action – Building 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.
- In the
BuildDeck
function, start off by declaring a few variables:function BuildDeck() { var totalRobots:int = 4; // we've got four robots towork with var card:Object; // this stores a reference to a card }
- Next, build a loop to step through each of the four colored robot types:
var card:Object; // this stores a reference to a card for(i=0; i<totalRobots; i++) { }
This loop will run four times because
totalRobots
is set to4
. Next, create an array calledRobotParts
that will house the names of the body parts ...
Get Unity 3.x 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.