unity AsyncOperation 进度保持为0
unity AsyncOperation progress stays 0
这是我在 unity 2017 中加载屏幕的代码,我知道它不起作用,操作进度保持为 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;
}
}
好的,伙计们,我有 2 个控制场景负载的脚本,但是一开始它不起作用,现在我删除了另一个脚本并且它工作正常
这是我在 unity 2017 中加载屏幕的代码,我知道它不起作用,操作进度保持为 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;
}
}
好的,伙计们,我有 2 个控制场景负载的脚本,但是一开始它不起作用,现在我删除了另一个脚本并且它工作正常