Unity 场景异步加载(加载界面的实现)

    public GameObject image;   //加载界面
    public Slider slider;   //进度条
    public Text text;      //加载进度文本
    public void LoadNextLeaver()
    {<!-- -->
        image.SetActive(true);  
        StartCoroutine(LoadLeaver());
    }
    IEnumerator LoadLeaver()
    {<!-- -->  
        AsyncOperation operation = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1); //获取当前场景并加一
       //operation.allowSceneActivation = false;
        while(!operation.isDone)   //当场景没有加载完毕
        {<!-- -->
            slider.value = operation.progress;  //进度条与场景加载进度对应
            text.text = (operation.progress * 100).ToString()+"%";
            yield return null;
        }
    }

 

posted @ 2023-09-01 16:16  李嘉伦伦伦伦  阅读(211)  评论(0)    收藏  举报