简体   繁体   English

游戏一旦建立便出现问题

[英]Porblem with game once builded

in my game to pass from one level to another you must answer some questions. 在我的游戏中,要从一个关卡传递到另一个关卡,您必须回答一些问题。 Each question has an associated image. 每个问题都有一个关联的图像。 For each level of play there is a different set of questions. 对于每个游戏级别,都有不同的问题集。 During the Unity game simulation there is no problem, but when I play the build of the game, the set of questions is not updated between one level and another, in fact the last question made at the first level is re-proposed. 在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);             
        }
    }
}

I solved the problem. 我解决了问题。 I just had to clear the list of questions before moving to the next level 在进入下一级别之前,我只需要清除问题列表即可

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM