Hello,
I am trying to load a scene named “GameLoading” which loads the game scene in the background, while updating a progress bar.
Here is my GameLoading script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameLoading : MonoBehaviour
{
public ProgressBar progressBar;
void Start()
{
StartCoroutine(loadSceneAsync());
}
private IEnumerator loadSceneAsync() {
AsyncOperation loading = SceneManager.LoadSceneAsync(SessionManager.getSceneToLoad());
while(!loading.isDone) {
progressBar.setValue(loading.progress/0.9f);
yield return null;
}
}
// Update is called once per frame
void Update()
{
}
}
And here is how I load the GameLoading scene from another scene :
private static void beginNewExerciseSession() {
SceneManager.LoadScene("GameLoading");
}
But it’s not working.
When the LoadScene() is called, it freezes Unity for ages before it actually loads the GameLoading. And when GameLoading is finally loaded, it stays for a milisecond before going on to the final game scene, so I’m pretty sure the final scene has already been loaded when GameLoading is displayed.
What seems to happen is that LoadScene() is waiting for the couroutine started in GameLoading to end, before actually loading GameLoading. So nothing happens at expected…
I’m pretty sure I’m doing something wrong, but I find this as a stranged behaviour.
Thank you ! Anselme.