游戏一旦建立便出现问题

时间:2019-06-29 15:25:22

标签: c# unity3d build

在我的游戏中,要从一个级别传递到另一个级别,您必须回答一些问题。每个问题都有一个关联的图像。对于每个游戏级别,都有不同的问题集。在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);             
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我只需要清除问题列表,然后再进入下一个级别