场景未加载

时间:2017-01-20 14:51:32

标签: c# android unity3d unity5 unity3d-2dtools

当我试图加载一个场景时,会发生一些奇怪的事情。

image1

生成错误的代码(我猜):

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;

    public class playSc : MonoBehaviour {
    public string levelToLoad;

    public Animator menumusic;
    public GameObject background;
    public GameObject text;
    public GameObject progressSlider;
    public Text progressText;
    public Slider progressBar;

    private int loadProgress = 0;


    public void close()
    {
        Application.Quit();
    }
    public void play()
    {
        menumusic.SetBool("FadeOUT", true);
        GameObject.Find("Clock").SetActive(false);
        progressText.text = "Think about the Universe to continue.\nThinking progress:";
        StartCoroutine(DisplayLoadingScreen("Game"));
    }
    public void credits()
    {
        menumusic.SetBool("FadeOUT", true);
        GameObject.Find("Clock").SetActive(false);
        progressText.text = "Think about your behaviour.\nThinking progress:";
        StartCoroutine(DisplayLoadingScreen("Credits"));
    }
    IEnumerator DisplayLoadingScreen(string level)
    {

        background.SetActive(true);
        text.SetActive(true);
        progressSlider.SetActive(true);

        AsyncOperation async = SceneManager.LoadSceneAsync(level);
        while (!async.isDone)
        {
            loadProgress = (int)(async.progress * 100);
            progressBar.value = loadProgress;
            yield return null;
        }
    }
}

我尝试使用Application.LoadLevel()但它仍然无法正常工作。它正在处理这段代码,但有一刻它就停止了。

0 个答案:

没有答案