我正在制作团结的第一场比赛。在这个游戏中,我的球员是一个碰到一些问号的球。当问号被触发时,它必须显示一个问题和答案。直到这里,每件事情都很好。现在我需要根据问题按a或b。如果答案是正确的,它会增加点数。但这是问题。 Unity不会等我按下按键。在我按下按钮并且游戏崩溃之前,Unity会通过代码。UNITY - 如何让团结等待,直到我按下我的键
void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.CompareTag("QuestionCube1"))
{
Question.text = "Which Number is bigger?";
Answer.text = "A.5 B.10";
if (Input.GetKeyDown(KeyCode.A))
{
gameController.minusQuestionScore();
}
else if (Input.GeyKeyDown(KeyCode.B))
{
gameController.addQuestionScore();
}
Question.text = "";
Answer.text = "";
}
}
//Sorry if the code is kinda all over the place I dont know how to pass the code here exactly. The gameController and the UI texts are declared and working
请确保您发布了最小的问题代码,这样可以更容易地理解和识别问题。 – Vect0rZ
您可以在发布代码时编辑原始帖子,在评论部分中它不可读。不是那么少,在输入之后重置Question.text和Answer.text的原因是什么? (为了回答你原来的问题,“等待”输入并不是一个好习惯)。首先,也许没有必要重新设置文本,或者有非常具体的理由这样做? – Vect0rZ
重置它们的原因是在移动时不会在我的脸上留下文字。那么如果这个想法不好,你能给我一个例子,它做我想要的吗?通过键盘回答问题。我必须完成这个到周六。 –