unity AsyncOperation进度保持为0

问题描述 投票:0回答:2

这是我的代码,用于2017年unity的加载屏幕,并且它不起作用,操作进度保持为0:(

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

public class LevelLoader : MonoBehaviour {
    public GameObject loadingScreen;
    public Slider slider;

    public void LoadLevel (string sceneIndex)
    {
        StartCoroutine (LoadAsynchronously(sceneIndex));
    }

    IEnumerator LoadAsynchronously (string sceneIndex)
    {
        AsyncOperation operation = SceneManager.LoadSceneAsync (sceneIndex);
        loadingScreen.SetActive (true);
        while (!operation.isDone) {
            float progress = Mathf.Clamp01 (operation.progress / 0.9f);
            Debug.Log (operation.progress);
            slider.value = progress;
            yield return null;
        }

    }
}
unity3d asynchronous loading
2个回答
0
投票
这些行在我以前的项目中工作正常,您可以尝试。

IEnumerator LoadScene() { yield return null; AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(SceneName); asyncOperation.allowSceneActivation = false; while (!asyncOperation.isDone) { //Output the current progress Text_Progress.text = "Loading progress: " + (asyncOperation.progress * 100) + "%"; // Check if the load has finished if (asyncOperation.progress >= 0.9f) { asyncOperation.allowSceneActivation = true; } yield return null; } }


0
投票
对不起,我有2个脚本来控制场景负载,是的,起初它不起作用,所以我删除了另一个脚本并正常工作了
© www.soinside.com 2019 - 2024. All rights reserved.