private IEnumerator Loading(string locationName, System.Action onLoadComplete) { GameState = GameStates.Loading; PrevLocationName = SceneManager.GetActiveScene().name; yield return(SceneManager.LoadSceneAsync(locationName)); Debug.Log("Loading complete: " + SceneManager.GetActiveScene().name); CurrentRoom = FindObjectOfType <Room>(); if (CurrentRoom != null) { CurrentRoom.Enter(PrevLocationName); if (locationsStates.ContainsKey(SceneManager.GetActiveScene().name)) { CurrentRoom.LoadState(locationsStates[SceneManager.GetActiveScene().name]); } } if (onLoadComplete != null) { onLoadComplete(); } if (SceneManager.GetActiveScene().name == mainMenuScene && PlayerController.IsInstance) { Destroy(PlayerController.Instance.gameObject); } yield return(new WaitForSeconds(0.1f)); if (SceneManager.GetActiveScene().name == mainMenuScene) { GameState = GameStates.MainMenu; } else { GameState = GameStates.Game; if (PrevLocationName != mainMenuScene) { AutoSave(); } } }