Time for action - modify the img argument

Because we're passing a new argument to the Card class, we have to modify Card to accept it.

  1. Change the Card class code from this:
    class Card extends System.Object
    {
    // (variables omitted for clarity)
    function Card()
    {
    img = "robot";
    }
    }
    

    to this:

    class Card extends System.Object
    {
    // (variables omitted for clarity)
    function Card(img:String)
    {
    this.img = img;
    }
    }
    
  2. Now, find the nested loop in the Start function where we added all our new cards to the aGrid array. Change it from this:
    for(var j:int=0; j<cols; j++)
    {
    aGrid[i][j] = new Card();
    }
    

    to this:

    for(var j:int=0; j<cols; j++)
    {
    var someNum:int = Random.Range(0,aCards.length);
    aGrid[i][j] = aCards[someNum];
    aCards.RemoveAt(someNum);
    }
    

What just happened? ...

Get Unity 3D 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.