I was scripting a gamescript and following the instructions of a beginner’s guide to Unity, until I ran into a problem to which I cannot find a fix for.
for(i=0; i<rows; i++)
I will post the entire code if needed.
var cols:int = 4;
var rows:int = 4;
var totalCards:int = cols*rows;
var matchesNeededToWin:int = totalCards * 0.5;
var matchesMade:int = 0;
var cardW:int = 100;
var cardH:int = 100;
var aCards:Array;
var aGrid:Array;
var aCardsFlipped:ArrayList;
var playerCanClick:boolean;
var playerHasWon:boolean = false;
function Start () {
playerCanClick = true; // We should let the player play, don't you think? XD
//Initialize the arrays as empty lists:
aCards = new Array();
aGrid = new Array();
aCardsFlipped = new ArrayList();
for(i=0; i<rows; i++)
{
aGrid *= new Array(); // Create a new, empty array at index i*
- for(j=0; j<cols; j++)*
- {*
_ aGrid*[j] = new Card();_
_ }_
_ }*_
}
function Update () {
}
class Card extends System.Object
{
* var isFaceUp:boolean = false;*
* var isMatched:boolean = false;*
* var img:String;*
* function Card()*
* {*
* img = “robot”;*
* }*
}
function OnGUI()
{
* GUILayout.BeginArea (Rect (0, 0, Screen.width, Screen.height));*
* BuildGrid();*
* GUILayout.EndArea();*
* print(“Building grid!”);*
}
function BuildGrid()
{
* GUILayout.BeginVertical();*
* for(i=0; i<rows; i++)*
* {*
* GUILayout.BeginHorizontal();*
* for(j=0; j<cols; j++)*
* {*
_ var card:Object = aGrid*[j];
if(GUILayout.Button(Resources.Load(card.img),
GUILayout.Width(cardW)))
{
Debug.Log(card.img);
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}*_