I’m making a loading scene. So from the scence B, when I click on the back button, I show a black scence then after loading I have my main menu.
Firstly the progress bar return me always 0. So when I rename my method LoadingScence called when the button is clicked by Sart and everything works fine. But when i want from the menu to go to the scene B, because the script of loading is activated, the Start make me go back to the menu, so I can’t acces to the scene B.
How could I do please ?
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 Start () //When I remane By LoadingScene for example, progress return always 0
{
StartCoroutine (LevelCoroutine ("Main Menu"));
}
IEnumerator LevelCoroutine (System.String nomScene)
{
LoadingScene.SetActive (true);
AsyncOperation async = SceneManager.LoadSceneAsync(nomScene);
while (!async.isDone) {
LoadingBar.fillAmount = async.progress/0.9f; //Async progress returns always 0 here
Debug.Log(async.progress);
textPourcentage.text = LoadingBar.fillAmount*100 + "%"; //I have always 0% because he fillAmount is always 0
yield return null;
}
}
}