using System.Collections; using Management; using UnityEngine; namespace State.Game { public class GameRunningState : MainGameState { public override void OnEnter(Machine machine) { base.OnEnter(machine); MainStateMachine.Respawn(); MainStateMachine.PlayerMovement.OnDeath += HandleDeath; MainStateMachine.PlayerMovement.GetPickup += HandleTutorial; MainStateMachine.PlayerMovement.EnterSpring += HandleTutorial; Services.Instance.ShowTransition(false); } private void HandleTutorial() { MainStateMachine.ShowTutorial(true); } private void HandleDeath() { MainStateMachine.StartCoroutine(DeathRoutine()); } private IEnumerator DeathRoutine() { // Hide the guts MainStateMachine.ShowDeathScreen(true); Services.Instance.SFX.PlayOneShot(MainStateMachine.DeathSound); // Cleanup before we remove player and fruits MainStateMachine.PlayerMovement.OnDeath -= HandleDeath; MainStateMachine.PlayerMovement.GetPickup -= HandleTutorial; MainStateMachine.PlayerMovement.EnterSpring -= HandleTutorial; MainStateMachine.Respawn(); // Reregister events MainStateMachine.PlayerMovement.OnDeath += HandleDeath; MainStateMachine.PlayerMovement.GetPickup += HandleTutorial; MainStateMachine.PlayerMovement.EnterSpring += HandleTutorial; // Wait a moment then restart the game yield return new WaitForSeconds(2f); MainStateMachine.ShowDeathScreen(false); } } }