Why my function does not work inside a corroutine used to load my scene.
Hi everyone,
So I want to load my scene and once done, I would like to execute a function. Here as you can see in my code, I load my scene with a coroutine and it works very well. However I would like, once my coroutine is finished to use my PlayGame (); function. But it does not work. The scene loads but the function does not run however the Debug.Log () inside my PlayGame () function are displayed in the Inspector. Does someone have an idea ?
public void LoadLevel (int sceneIndex)
{
StartCoroutine (LoadAsynchronously (sceneIndex));
}
IEnumerator LoadAsynchronously (int sceneIndex)
{
AsyncOperation operation = SceneManager.LoadSceneAsync (sceneIndex);
while (! operation.isDone)
{
float progress = Mathf.Clamp01 (operation.progress / 0.9f);
Debug.log (progress);
if (progress == 1)
{
PlayGame ();
}
yield return null;
}
}
Your answer
Follow this Question
Related Questions
Need a Script for Changing Scenes after pressing E to open locked door once a key has been found. 0 Answers
Weird problem with simple boolean and "if" statement [C#] 0 Answers
WaitForSeconds in Coroutines do not work. 0 Answers
Waiting for Saving/Loading? 2 Answers
How can i change the value of a variable from an IEnumerator 0 Answers