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; } 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.Respawn(); // Reregister events MainStateMachine.PlayerMovement.OnDeath += HandleDeath; // Wait a moment then restart the game yield return new WaitForSeconds(2f); MainStateMachine.ShowDeathScreen(false); } } }