嘿家伙我正在为一个类项目的一些代码工作,由于某种原因,我在课堂上得到的演示代码的工作方式不一样。错误没有做任何,因为我可以得到一些帮助调试我知道它可能会减速。非常感谢。其中ifFaceUP和IMG定义为什么变量没有显示为对象的成员?
class Card extends System.Object
{
//is the card face up
var ifFaceUp:boolean = false;
//has the card been matched
var ifMatched:boolean = false;
//image for the card
var img: String;
//constructor
function Card(img : String)
{
this.img = img;
}
}
错误
function BuildGrid()
{
//begin with a BeginVertical() call so that controls
//are stacked vertically
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
//begin loopping for the rows
for(var i=0; i<rows; i++)
{
//call BeginHorizontal() so that controls are stacked
//horizontally
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
//begin looping for the columns
for(var j=0; j<cols; j++)
{
//getting the card object that resides
//at this location in the array
var card:Object = aGrid[i][j];
//the definition for the backside (visible part for the card
var img : String;
//check if the card is face up, if so, show the robot part
//if not show the wrench
if(card.ifFaceUp)
{
img = card.img;
}
else
{
img = "wrench";
}
//create a button using a picture instead of
//text. Getting the picture from the Resources
if(GUILayout.Button(Resources.Load(img),
GUILayout.Width(cardW)))
{
flipCardFaceUp(card);
//print to the debug the name of the picture
Debug.Log(card.img);
}
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}//end buildGrid
var card:Object = aGrid [i] [j]; aGrid包含哪些类型的对象?后来你尝试:card.ifFaceUp,但ifFaceUp不是Object的成员,所以它不会工作吗?您应该将卡转换为正确的类型:var card:Card = aGrid [i] [j]; – HMR 2013-03-05 04:50:23
也许会添加C#标记,看起来像您发布的代码是C# – HMR 2013-03-05 04:51:24
aGrid [i] [j]是一个2d对象数组。 – 2013-03-05 04:52:24