我找到了测验游戏应用程序的错误,但我不知道是什么原因或如何解决。所有问题和选择都收集在一个数组中,一旦场景开始,脚本便开始工作。
它工作得很好,出现问题并做出应有的选择。
我想做的就是修复我遇到的这个错误,但是我不知道从哪里开始,我想寻求帮助
由于我试图弄清正在发生的事情,并且无法确定为什么会发生,因此我尝试重新制作整个脚本,并尝试从头到尾重新创建相同的东西或类似的东西,但我仍然得到相同的结果结果。 Idk也许我只是在错误地对待它
[System.Serializable]
public class Questions
{
public string question;
public string answer;
}
经理
public class Manager : MonoBehaviour
{
/*Calls Questions.cs
*Creates an array and calls it [questions]
*Creates a List and calls it [unansweredQuestions] with the format of
*Questions.cs
*Creates a private variable and calls it [currentQuestion]
*/
public Questions[] questions;
public static List<Questions> unansweredQuestions;
public static Questions currentQuestion;
[SerializeField]
public Text questionText;
//gameObject
public Text firstChoiceanswer;
public Text secondChoiceanswer;
//gameObject's text
public Text A1;
public Text A2;
[SerializeField]
public float TimeBetweenQuestions = 1f;
//waits a few seconds
void Start()
{
if (unansweredQuestions == null || unansweredQuestions.Count == 0)
{
unansweredQuestions = questions.ToList<Questions>();
}
SetCurrentQuestion();
}
void SetCurrentQuestion()
{
int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
currentQuestion = unansweredQuestions[randomQuestionIndex];
//Random position where the choices will go buttons
int randomAnswerIndex = Random.Range(0, 2);
if(randomAnswerIndex == 0)
{
A1.text = currentQuestion.answer;
A2.text = currentQuestion.wronganswer;
} else if (randomAnswerIndex == 1)
{
A2.text = currentQuestion.answer;
A1.text = currentQuestion.wronganswer;
}
//changes the text with a random question
questionText.text = currentQuestion.question;
}
//Checks the answer in A1
public void AnswerChecking1()
{
if (currentQuestion.answer == firstChoiceanswer.text)
{
Debug.Log("Correct");
}
else
{
Debug.Log("Wrong");
}
WaitTransitionToNextQuestion();
LoadNextQuestion();
}
//Checks the answer in A2
public void AnswerChecking2()
{
if (currentQuestion.answer == secondChoiceanswer.text)
{
Debug.Log("Correct");
}
else
{
Debug.Log("Wrong");
}
WaitTransitionToNextQuestion();
LoadNextQuestion();
}
//waits for abit to change question
IEnumerator WaitTransitionToNextQuestion()
{
yield return new WaitForSeconds(TimeBetweenQuestions);
}
//Changes the Question after answered
public void LoadNextQuestion()
{
SetCurrentQuestion();
}
}
菜单至少包含4个不同的主题,用户必须从这4个主题中进行选择,然后将用户转移到该主题的另一个场景。
每当我开始一个新游戏并选择一个主题(例如数学)时,或者当我回到主题选择并单击另一个主题(例如英语)时,都会出现此问题,而不是显示新的问题和选择,以前的主题(第一个主题)的问题和选择仍然出现,而不是新选择的主题,我不知道为什么要这么做。