Quite simple actually... use the Slider from the UI and be aware that an AsyncOperation of progress value 0.9f means that it's done, at least when it comes to loading a scene.
Here's the code:
public Slider LoadingProgressSlider;
private void Start()
{
LoadingProgressSlider.gameObject.SetActive(false);
}
public void GoToScene(string scene)
{
StartCoroutine(LoadingSceneRealProgress(scene));
}
AsyncOperation _sceneAO;
IEnumerator
LoadingSceneRealProgress(string sceneName)
{
LoadingProgressSlider.gameObject.SetActive(true);
yield return new WaitForSeconds(0.5f);
_sceneAO =
SceneManager.LoadSceneAsync(sceneName);
_sceneAO.allowSceneActivation = false;
while (LoadingProgressSlider.value < 1f)
{
LoadingProgressSlider.value =
_sceneAO.progress / 0.9f;
yield return null;
}
_sceneAO.allowSceneActivation = true;
}
Comments
Post a Comment