【发布时间】:2019-11-11 02:37:34
【问题描述】:
在我的游戏中,要从一个级别传递到另一个级别,您必须回答一些问题。每个问题都有一个关联的图像。对于每个级别的游戏,都有一组不同的问题。在Unity游戏模拟过程中没有问题,但是当我玩游戏的构建时,问题集并没有在一个级别和另一个级别之间更新,实际上第一级提出的最后一个问题是重新提出的。
public class MiniGameManager : MonoBehaviour
{
public Question[] questions;
private static List<Question> unanswered;
private Question currentQuestion;
[SerializeField]
private Image sprite;
[SerializeField]
private float timeQuestion = 1f;
public static int contCorrect;
public Button firstSelected;
void Start()
{
if(unanswered == null || unanswered.Count == 0)
{
unanswered = questions.ToList<Question>();
}
contCorrect = 0;
SetCurrentQuestion();
firstSelected.Select();
}
void SetCurrentQuestion()
{
int index = UnityEngine.Random.Range(0, unanswered.Count);
currentQuestion = unanswered[index];
sprite.sprite = currentQuestion.questionSprite;
}
IEnumerator ToQuestion()
{
unanswered.Remove(currentQuestion);
yield return new WaitForSeconds(timeQuestion);
SetCurrentQuestion();
}
public void UserSelectFirst()
{
if (currentQuestion.answer == 0)
{
currentQuestion.correct = true;
countCorrect++;
}
else
{
currentQuestion.correct = false;
}
if (unanswered.Count > 1)
{
StartCoroutine(ToQuestion());
}
else
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1, LoadSceneMode.Single);
}
}
public void UserSelectSecond()
{
if (currentQuestion.answer == 1)
{
currentQuestion.correct = true;
countCorrect++;
}
else
{
currentQuestion.correct = false;
}
if (unanswered.Count > 1)
{
StartCoroutine(ToQuestion());
}
else
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1, LoadSceneMode.Single);
}
}
public void UserSelectThird()
{
if (currentQuestion.answer == 2)
{
currentQuestion.correct = true;
countCorrect++;
}
else
{
currentQuestion.correct = false;
}
if (unanswered.Count > 1)
{
StartCoroutine(ToQuestion());
}
else
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1, LoadSceneMode.Single);
}
}
public void UserSelectFourth()
{
if (currentQuestion.answer == 3)
{
currentQuestion.correct = true;
countCorrect++;
}
else
{
currentQuestion.correct = false;
}
if (unanswered.Count > 1)
{
StartCoroutine(ToQuestion());
}
else
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1, LoadSceneMode.Single);
}
}
}
【问题讨论】: