- Home /
Being in scene1 I want to load scene2, but also to disable scene1. How can I do that correctly?
Hello!
I have one scene in which player play the game and when he presses a UI button I've made I'd like to load scene2.
Firstly I tried that:
public void LoadScene2()
{
SceneManager.LoadScene("scene2");
}
but when it loads, I listen sounds from the first scene (I supposed the first scene was still in work).
So, I tried this in order to disable the first scene, but it didn't help:
public void LoadScene2()
{
SceneManager.LoadScene("scene2");
SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().buildIndex);
}
Answer by xorap · Jun 10, 2018 at 11:59 PM
Here is how I've successfully loaded scenes.
IEnumerator LoadScene2 ()
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync ("scene2");
while (!asyncLoad.isDone) {
Debug.Log ("Loading ...");
yield return null;
}
}
You'll have to call StartCoroutine(LoadScene2); rather than LoadScene2(); let me know if it works.
Your answer
Follow this Question
Related Questions
LoadSceneOnClicks.LoadAsynchronously(int)': not all code paths return a value 1 Answer
Load scene in unet behind a loading screen 1 Answer
Which is the correct way to save character preferences like clothes? 1 Answer
I need help (go to the next scene after a few seconds after creating the explosion) 2 Answers