【问题标题】:Porblem with game once builded游戏构建后出现问题
【发布时间】: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);             
        }
    }
}

【问题讨论】:

    标签: c# unity3d build


    【解决方案1】:

    我解决了这个问题。我只需要在进入下一个级别之前清除问题列表

    【讨论】:

      猜你喜欢
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 2016-03-05
      • 2019-02-19
      相关资源
      最近更新 更多