I’ve been getting several errors for this script, but I knocked it down to just this one, object’ does not support slicing. Line 65,26. This question has been answered before, but the other answers haven’t helped me on this part.
#pragma strict
var cols:int = 4;//the number of columns in the card grid
var rows:int = 4;//the number of rows in the grid
var totalCards:int = cols*rows;
var matchesNeededToWin:int = totalCards * 0.5;//8 matches are needed to clear the board
var matchesMade:int = 0;//at the start the player hasn't made any matches
var cardW:int = 100;//Each card's width is 100 pixels
var cardH:int = 100;//Each card's height is 100 pixels
var aCards:Array;// store the cards created in this array
var aGrid:Array;//keep track of shuffled, dealt cards in this array
var aCardsFlipped:ArrayList;//stores the two cards that the player flips over
var playerCanClick:boolean;//use this flag to prevent player from clicking buttons at certain times
var playerHasWon:boolean = false;//stores whether or not the player has won
var i:int;
var j:int;
function Start ()
{
playerCanClick = true;
//initialize the arrays as empty lists:
aCards = new Array();
aGrid = new Array();
aCardsFlipped = new ArrayList();
for(var i=0; i<rows; i++)
{
var acrds:Array=new Array();
for(var j=0; j<cols; j++)
{
acrds[j] = new Card();
}
aGrid[j]=acrds;
}
}
function OnGUI ()
{
GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height));//this will be the width and height of the screen and it will start at the screen origin
BuildGrid();//builds the grid of card buttons
GUILayout.EndArea();
print("building grid!");
}
class Card extends System.Object
{
var isFaceUp:boolean = false; //determines whether or not the card has been flipped
var isMatched:boolean = false;//is set to true when the card has been matched
var img:String;
function Card()
{
img = "robot";
}
}
function BuildGrid()
{
GUILayout.BeginVertical();
for(i=0; j<cols; j++)
{
GUILayout.BeginHorizontal();//BeginHorizontal/EndHorizontal to make card buttons stacked horizontally instead of vertically
for(j=0; j<cols; j++)
{
var card:Card = aGrid*;*
if(GUILayout.Button(Resources.Load(card.img),
- GUILayout.Width(cardW)))//keeps the card from filling the width of the layout area*
{
Debug.Log(card.img);
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}