这是我的代码,用于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;
}
}
}
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;
}
}