I everybody, I’m making a loading scence using scene manager LoadScenceAsync. I would use the progress value to have an loading UI, but I have always 0. I found anywhere an answer.
Do you know please, how could I do ?
here my code :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour {
public GameObject LoadingScene;
public Image LoadingBar;
public Text textPourcentage; //The text with the percentage increasing
public void LoadLevel (string nomScene) //The name of the scene
{
StartCoroutine (LevelCoroutine (nomScene));
}
IEnumerator LevelCoroutine (System.String nomScene)
{
LoadingScene.SetActive (true);
AsyncOperation async = SceneManager.LoadSceneAsync(nomScene);
while (!async.isDone) {
LoadingBar.fillAmount = async.progress ; //Async progress returns always 0 here
Debug.Log(async.progress);
textPourcentage.text = LoadingBar.fillAmount + "%"; //I have always 0% because he fillAmount is always 0
yield return null;
}
}
}