using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; using Photon.Pun; public class DeathScene : MonoBehaviour { [Header("Animator Settings")] [SerializeField] private Animator animator; [SerializeField] private string deathOrJumpscareAnim = "animation"; [Header("Scene Settings")] [SerializeField] private string sceneName = "Death"; [SerializeField] private float loadDelay = 2f; [Header("Photon Settings")] [SerializeField] private bool leavePhotonRoom = true; private void OnEnable() { StartCoroutine(HandleSceneChange()); } IEnumerator HandleSceneChange() { if (animator != null) { AnimatorStateInfo state = animator.GetCurrentAnimatorStateInfo(0); while (!state.IsName(deathOrJumpscareAnim) || state.normalizedTime < 1f) { state = animator.GetCurrentAnimatorStateInfo(0); yield return null; } } Debug.Log("Animation finished. Waiting " + loadDelay + " seconds before loading scene..."); yield return new WaitForSeconds(loadDelay); SceneManager.LoadScene(sceneName); if (leavePhotonRoom && PhotonNetwork.InRoom) { Debug.Log("Leaving Photon room..."); PhotonNetwork.LeaveRoom(); } } }