我对编码真的很陌生,我遇到了我的第一个问题......看过它 4 小时后,我意识到我可能需要一些帮助。
该代码用于 4 个按钮,所有按钮的代码都非常相似(实际上除了 ID 变量外几乎相同),但其中 2 个在加载时说 'argumentoutofrangeexception index',尽管索引相同。(或者我认为)
我在代码下面链接了一个不工作的按钮和一个工作的其他按钮+测试控件:
不工作按钮
public class Answer3script : MonoBehaviour {
List<string> thirdchoice = new List<string>() { "first choice", "second choice", "third choice", "fourth", "fifth"};
public static string answerCorrect3 = "n";
void Update () {
if (Textcontrol.randQuestion > -1)
{
GetComponentInChildren<Text>().text = thirdchoice[Textcontrol.randQuestion];
}
if (Textcontrol.correctAnswer[Textcontrol.randQuestion] == Textcontrol.buttonSelected)
{
answerCorrect3 = "y";
}
}
}
工作按钮
public class Answer2script : MonoBehaviour {
List<string> secondchoice = new List<string>() { "first choice", "second choice", "third choice", "fourth choice", "fifth choice" };
public static string answerCorrect2 = "n";
void Update () {
if (Textcontrol.randQuestion > -1)
{
GetComponentInChildren<Text>().text = secondchoice[Textcontrol.randQuestion];
}
if (Textcontrol.correctAnswer[Textcontrol.randQuestion] == Textcontrol.buttonSelected)
{
answerCorrect2 = "y";
// if (answerCorrect2 == "y")
// {
// image.color = Color.green;
// }
}
}
}
文本控制:
public class Textcontrol : MonoBehaviour {
List<string> questions = new List<string>() { "This is the first question", "second", "third", "fourth", "fifth" };
public static List<string> correctAnswer = new List<string>() { "Answer1", "Answer2", "Answer3", "Answer4", "Answer4" };
public static string buttonSelected;
public static string choiceSelected = "n";
public static int randQuestion=-1;
}
}
}
}
为格式非常糟糕的代码道歉,我无法让它工作!
慕的地6264312
相关分类