// Removes the old level and loads in new level public Scene LoadLevel(string name, LoadSceneAction OnFinishLoad) { GameObject g = GameObject.Find("Tile Map"); if (g != null) { Destroy(g); } StartCoroutine(LoadLevelAsync(name, OnFinishLoad)); return(pastLevel); }
// Loads scene and starts game once finished private IEnumerator LoadLevelAsync(string name, LoadSceneAction OnFinishLoad) { if (pastLevel.isLoaded) { AsyncOperation asyncUnloadLevel = SceneManager.UnloadSceneAsync(pastLevel); while (!asyncUnloadLevel.isDone) { yield return(null); } } Application.backgroundLoadingPriority = ThreadPriority.High; AsyncOperation asyncLoadLevel = SceneManager.LoadSceneAsync(name, LoadSceneMode.Additive); while (!asyncLoadLevel.isDone) { yield return(null); } pastLevel = SceneManager.GetSceneByName(name); if (OnFinishLoad != null) { OnFinishLoad.Invoke(pastLevel); } }