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.
- Find this line in your
BuildGrid
function:if(GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW)))
- Change
card.img
toimg
so that the line reads like this:if(GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW)))
- Just above that line, find the
card
variable definition:var card:Object = aGrid[i][j];
- Insert this line just after it:
var img:String;
- Finally, after that line, write this conditional statement:
if(card.isFaceUp) { img = card.img; } else { img = "wrench"; }
- 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.