How to assign textures to specific grid locations?

Hey All,

The code I have below is for building a deck in a memory game. The images that are being assigned for when the card is flipped and matched are fine but I would like to assign different images to each of the back of the cards. Currently, it is assigning the same texture to all of them and so am wondering how I can go about applying a different texture to each grid location for the gui button.

Thanks!

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++)
	{
		var card:Card = aGrid[i,j];
		var img:String;
		if(card.isMatched)
		{
			img = "back";
		}else{
		
		if(card.isFaceUp)
		{
			img = card.img;
		}else{
			img = "set1_1";
		}

Each card could have 3 variables. One for each image.

  1. Front Image - Each card has it’s own unique front image
  2. Back Image - Each card has it’s own unique back image
  3. Current Image - The image that would either be front or back

Front and Back images would be your “default” images for each card. These 2 would not change and wouldn’t be displayed. Current image would be the image that you would use, display and assign it either Front or Back image.

Another idea for back images is instead of giving each card a default back image, you could have a collection of back images stored in an array or list. And then give a card one of the images from the collection to your current image when you want a card to show a back image. When you want the card to go back to showing the Front image, just assign the card’s front image to card’s Current image.

In this case, I have a 2x4 grid for a total of 8 images.