Time for action – making 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() { GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); for(var i:int=0; i<rows; i++) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); for(var j:int=0; j<cols; j++) { ...