[英](Unity) My Text UI not updating
Ok, so, i try to make something like a quizz, where an array of strings has to be shown to the Text UI. 好的,所以,我尝试进行类似测验的操作,其中必须将字符串数组显示给Text UI。 Thing is, the question updates in the inspector after i answer it correctly, however it doensn't on the game screen. 问题是,在我正确回答问题后,问题会在检查器中更新,但是在游戏屏幕上却没有。 Prob a noob mistake, sorry i'm newbie. 可能是一个菜鸟错误,对不起,我是新手。
public string[] quesitons = new string[] { "2+2 = ?", "1+1 = ?", "3+3 = ?" };
public string[] answers = new string[] { "4", "2", "6" };
public int i = 0;
[SerializeField]
private InputField _input;
//Main
public string currentQ;
public string currentA;
public Text questionText;
public void GetInput(string input)
{
if (input == answers[i])
{
Debug.Log("Correct");
i++;
questionText.text = quesitons[i];
currentQ = quesitons[i];
currentA = answers[i];
}
else
{
Debug.Log("Wrong");
}
}
void Start()
{
currentQ = quesitons[i];
questionText.text = quesitons[i];
currentA = answers[i];
}
}
The code you have posted should work. 您发布的代码应该可以使用。 Maybe you've missed the text updation line from the GetInput function there? 也许您错过了GetInput函数中的文本更新行? Anyway I've posted a refactored code here. 无论如何,我在这里发布了重构代码。 Replace your GetInput and Start functions with below code, and test.. 用下面的代码替换GetInput和Start函数,然后进行测试。
public void GetInput(string input) {
if (input == currentA) {
Debug.Log("Correct");
i++;
LoadQuestionAnswer();
}
else {
Debug.Log("Wrong");
}
}
void Start() {
LoadQuestionAnswer();
}
void LoadQuestionAnswer() {
currentQ = quesitons[i];
currentA = answers[i];
questionText.text = currentQ;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.