private void OnStateChange() { if (CurrentMusicInstance != null) { if (!(NextGameState == GameState.Menu && GameState == GameState.Menu)) { CurrentMusicInstance.Stop(); } else if (CurrentMusicInstance.State == SoundState.Paused) { CurrentMusicInstance.Play(); } } if (NextGameState == GameState.GameOver) //Answer me Snake...Snake?! SNAKEEEEEEE!!!" { if (GameOverMenu.GameOverReason == GameOverReason.Win) { CurrentScreen = GameWinMenu; GameWinMenu.LastPlayerScore = Player.Score; } else { CurrentScreen = GameOverMenu; GameOverMenu.Awake(); } GameState = GameState.Menu; Player.OnGameOver(); LevelManager.OnGameOver(); NextGameState = GameState.None; CurrentMusicInstance = MenuMusic.CreateInstance(); CurrentMusicInstance.IsLooped = true; CurrentMusicInstance.Play(); } else { if (NextGameState == GameState.Menu) { switch (NextUIType) { case UIType.MainMenu: { CurrentScreen = MainMenu; break; } case UIType.LevelTransition: { LevelTransition.ResetState(); CurrentScreen = LevelTransition; break; } case UIType.GameOver: { CurrentScreen = GameOverMenu; break; } case UIType.Leaderboard: { CurrentScreen = Leaderboard; break; } default: { break; } } } else if (NextGameState == GameState.Game) { LevelManager.NextLevel(); } else if (NextGameState == GameState.NewGame) { NewGame(); } if (NextGameState == GameState.Game) { CurrentMusicInstance = GameMusic.CreateInstance(); CurrentMusicInstance.IsLooped = true; } else if (CurrentMusicInstance == null || (GameState == GameState.Menu && CurrentScreen != LevelTransition && !(NextGameState == GameState.Menu && GameState == GameState.Menu))) { CurrentMusicInstance = MenuMusic.CreateInstance(); CurrentMusicInstance.IsLooped = true; CurrentMusicInstance.Play(); } GameState = NextGameState; } NextGameState = GameState.None; NextUIType = UIType.None; }