using System.Collections; using System.Collections.Generic; using UnityEngine; using Ktyl.Util; public class PlayerDeath : MonoBehaviour { public Animator animator; public GameObject fadeScreen; private GameObject player; [SerializeField] private SerialVector3 _respawnPosition; [SerializeField] private GameEvent _playerDeath; [SerializeField] private GameEvent _playerRespawn; public void Respawn() { StartCoroutine(RespawnPlayerCR()); } // Corountine to trigger death animation, disable player movement, play fade, // respawn player at last safe position and then play fade in animation and re-enable player movement. public IEnumerator RespawnPlayerCR() { animator.SetTrigger("IsDead"); _playerDeath.Raise(); yield return new WaitForSeconds(0.5f); fadeScreen.GetComponent().SetTrigger("fadeToBlack"); yield return new WaitForSeconds(1.5f); // move player to respawn position player.transform.position = _respawnPosition; fadeScreen.GetComponent().SetTrigger("fadeToClear"); yield return new WaitForSeconds(0.5f); _playerRespawn.Raise(); yield return null; } }