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(); ...

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.