【发布时间】:2015-12-15 19:38:40
【问题描述】:
我无法理解为什么我的代码存在“意外符号”。我正在为一个项目使用 for 循环,这几行代码给我带来了问题。我猜这与不在某处放置括号/分号有关,但我不知道它会在哪里。我可以得到一些帮助来确定我需要在哪里更正这个错误吗? enter image description here
这是存在错误的完整代码
// Use this for initialization
void Start()
{
string[] imagesNames = new string[3] { "portrait01", "portrait02", "portrait03" };
//images [0] = CreateSprite ("portrait01");
//images[1] = CreateSprite ("portrait02");
//images[2] = CreateSprite ("portrait03");
string[] professionNames = new string[3] {"Karate fighter", "Ninja Figher", "Samurai Fighter"};
string[] professionDescriptions = new string[3] { "Use hand to hand combat for powerful attacks! Req: Strength = 13 and Special = 10",
"Use high stealth and sneak attacks to suprize you enemies! Req: Speed = 15 or Strength = 9",
"Use your wisdom to reverse attacks with 2x the power! Req: Wisdom = 14 or Special = 13" };
string[] professionImageNames = new string[3] { "profession01", "profession02", "profession03"};
int[] [] minRequirements = { new int [3] {11, 11, 12}, new int[3] {11,13,12}, new int[3] {11,11,16} };
professions = new Profession[3]
for (int i = 0; i < 3; i++)
{
professions[i] = CreateProfession (name[i], description[i], profimages[i], minRequirements[i]);
}
for (int i = 0; i < professionNames.Length; i++) //this starts at least one of the loops
{
profession[i] = createItem(professionNames[i], professionDescriptions[i], professionImageNames[i], minRequirements[i]);
}
//profession01 = createItem("Karate Fighter", "Use hand to hand combat for powerful attacks!", "portrait01");
//profession02 = createItem("Ninja Fighter", "Use high stealth and sneak attacks to suprize you enemies!", "portrait02");
//profession03 = createItem("Samurai Fighter", "Use your wisdom to reverse attacks with 2x the power!", "portrait03");
for (int i = 0; i < imagesNames.Length; i++) //creates a for loop for the images
{
images[i] = CreateSprite(imagesNames[i]); //makes it so the images come from CreatSprite
//array
}
portraitImage.sprite = images[currentImage]; //renders the current images
profession.characterManager = this;
for (in i = 0; i < minRequirement.Length; i++) {
profession.requirements [i] = profession.CreateRequirement { Attribute [i], minRequirement[i];
}
return profession;
}
【问题讨论】:
-
首先,这个
professions = new Profession[3]需要一个; -
另外,您的最后一个 for 循环在“int i = 0;”中缺少“t”
-
你的变量名不一致