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 - make the cards two-sided

We'll write some logic so that the cards show one image or another depending on whether or not they've been flipped over.

  1. Find this line in your BuildGrid function:
    if(GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW)))
    
  2. Change card.img to img so that the line reads like this:
    if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
    
  3. Just above that line, find the card variable definition:
    var card:Object = aGrid[i][j];
    
  4. Insert this line just after it:
    var img:String;
    
  5. Finally, after that line, write this conditional statement:
    if(card.isFaceUp)
    {
    img = card.img;
    }
    else
    {
    img = "wrench";
    }
    
  6. The whole function should look like this when you're finished:
    function BuildGrid() { UILayout.BeginVertical(); ...

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