I am trying to switch from a main menu scene to a game scene. I have a splash screen setup to use during the transition however I run into problems. I have tried it different ways with different problems. First I tried this:
public void MountainCampButton() {
gameObject.SetActive(false);
splashScreen.GetComponent<SplashScreen>().SetLevel("Mountain Camp");
splashScreen.SetActive(true);
SceneManager.LoadSceneAsync("MountainCamp");
}
Thinking this should load the new scene and show it, then unload the old scene. This happens however right before the new scene is displayed the main menu is shown just for a fraction of a second. So I found that possibly the old scene is unloaded first before the new scene is loaded so I tried this:
void OnEnable() {
SceneManager.sceneLoaded += OnLevelFinishedLoading;
}
public void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode) {
switch (scene.name) {
case "MountainCamp":
SceneManager.sceneLoaded -= OnLevelFinishedLoading;
SceneManager.SetActiveScene(SceneManager.GetSceneByName("MountainCamp"));
SceneManager.UnloadSceneAsync("MainMenu");
break;
}
}
public void MountainCampButton() {
gameObject.SetActive(false);
splashScreen.GetComponent<SplashScreen>().SetLevel("Mountain Camp");
splashScreen.SetActive(true);
SceneManager.LoadSceneAsync("MountainCamp", LoadSceneMode.Additive);
}
Thinking I would be able to manually load and unload however this results in a warning in the load saying
Unloading the last loaded scene Assets/Levels/MainMenu.unity(build index: 0), is not supported. Please use SceneManager.LoadScene()/EditorSceneManager.OpenScene() to switch to another scene.
Which leaves my game still showing the main menu. Can anyone provide me with some assistance on making a smooth scene transition?