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

Let's set up a deck-building function called BuildDeck.

  1. Create a new function called BuildDeck. Write this function outside of and apart from your other functions make sure it's not trapped inside the curly brackets of one of your other functions.
    function BuildDeck()
    {
    }
    
  2. Call the BuildDeck function in the Start function, just after you define the three card-related arrays:
    function Start()
    {
    playerCanClick = true; // We should let the player play, don't you think?
    // Initialize the arrays:
    aCards = new Array();
    aGrid = new Array();
    aCardsFlipped = new ArrayList();
    BuildDeck();
    // (the rest of this function has been omitted)
    }
    

The very first function that gets called in our script is the Start 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