using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; using Cinemachine; public class PlayerDeath : MonoBehaviour { [SerializeField] private PlayableDirector _GhostKillsPlayer; [SerializeField] private GameObject cameraForLoad; CinemachineBrain cinemachineBrain; public bool playerIsDead; private static PlayerDeath _instance; public static PlayerDeath GetInstance() { return _instance; } private void Awake() { if (!_instance) { _instance = this; } cinemachineBrain = GetComponentInChildren(); } void Update() { if(Sanity.GetInstance().currentSanity <= 0f && !playerIsDead) { LowSanityGhostKillsPlayer(); } } public void LowSanityGhostKillsPlayer() { RaycastManager.GetInstance().enabled = false; PlayerManager.GetInstance().DisablePlayerMovement(); PlayerManager.GetInstance().DisablePlayerCameraMovement(); cinemachineBrain.enabled = true; _GhostKillsPlayer.Play(); playerIsDead = true; } public void OnPlayerDeathLoadGame() { print("Player died and now the game is loading"); //Sanity.GetInstance()._sanity = Sanity.GetInstance()._sanityMaxValue; playerIsDead = false; Instantiate(cameraForLoad); //I ADDED TO SEE IF IT WORKS!!!! Destroy(GameSystemsManager.GetInstance().transform.gameObject); //---------------------------------------------------------------- LoadController.GetInstance().LoadGame(); } }