diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30Controller.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30Controller.cs index dc012b9..472f22c 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30Controller.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30Controller.cs @@ -20,8 +20,10 @@ public class Anomaly30Controller : AbstractAnomalyObject private bool isAnomalyStopped = false; // Flag to stop attaching scripts private Anomaly30_thunderstorm thunderstorm; - void Start() + public override bool StartAnomaly() { + bool res = base.StartAnomaly(); + gameManager = GameObject.Find("GameManager").GetComponent(); player = GameObject.Find("Player"); mainCamera = Camera.main; @@ -46,8 +48,30 @@ void Start() // 20초 후 창문 열기 중지 StartCoroutine(EndWindowsOpeningAfterTime(20f)); + + return res; + } + + private void Start() + { + StartAnomaly(); + } + + public override bool ResetAnomaly() + { + bool res = base.ResetAnomaly(); + + isAnomalyStopped = true; + StopAnomaly(); + gameManager.SetStageClear(); + + thunderstorm.DestroyThunderstormScreen(); // 비디오 화면 제거 + CloseAllWindows(); + + return res; } + private IEnumerator ApplyAnomalyWindowScriptsAndCollider() { yield return new WaitForSeconds(2f); // 2초 후 시작 @@ -82,13 +106,7 @@ private IEnumerator ApplyAnomalyWindowScriptsAndCollider() private IEnumerator EndWindowsOpeningAfterTime(float time) { yield return new WaitForSeconds(time); - - isAnomalyStopped = true; - StopAnomaly(); - gameManager.SetStageClear(); - - thunderstorm.DestroyThunderstormScreen(); // 비디오 화면 제거 - CloseAllWindows(); + ResetAnomaly(); } private void CloseAllWindows() diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs index b3d722c..2761889 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs @@ -1,8 +1,10 @@ using System.Collections; using UnityEngine; -public class Anomaly30_window : InteractableObject, IInteractable +public class Anomaly30_window : AbstractAnomalyInteractable { + public override string Name { get; } = "Anomaly30_window"; + public float swingAngle = 60f; private const float soundDuration = 0.672f; // 사운드 주기(창문 열리고 닫히는 한 주기과 맞추기 위함) private readonly float swingSpeed = Mathf.PI / soundDuration; @@ -21,8 +23,15 @@ public class Anomaly30_window : InteractableObject, IInteractable private AudioSource audioSource; private static GameObject coroutineRunner; - void Start() + private void Start() { + StartAnomaly(); + } + + public override bool StartAnomaly() + { + bool res = base.StartAnomaly(); + anomalyManager = FindObjectOfType(); // 창문 닫을 때 복구할 초기 rotation @@ -41,7 +50,10 @@ void Start() // 15초 동안 이 창문을 닫지 않을 시 발동 Invoke(nameof(EndAnomaly), anomalyDuration); - } + + return res; + } + private IEnumerator SwingWindow() { @@ -87,13 +99,18 @@ private IEnumerator CloseWindowCoroutine() // initial rotation으로 return animation while (elapsedTime < closeDuration) { + if (this == null || transform == null) yield break; + transform.rotation = Quaternion.Slerp(currentRotation, initialRotation, elapsedTime / closeDuration); elapsedTime += Time.deltaTime; yield return null; } - transform.rotation = initialRotation; - Destroy(this); + if (this != null && transform != null) + { + transform.rotation = initialRotation; + Destroy(this); + } } private void EndAnomaly() @@ -102,8 +119,6 @@ private void EndAnomaly() { anomalyManager.PlayerDieFromStorm(transform.position); } - - Destroy(this); } public override string GetInteractionPrompt() @@ -111,13 +126,6 @@ public override string GetInteractionPrompt() return "Press Left Click to close the window."; } - public override bool CanInteract(float distance) - { - return !hasInteracted; - } - // modified by 신채환 - // CanInteract 메서드가 거리를 인자로 받도록 변경 - public override void OnInteract() { if (hasInteracted) return; @@ -125,6 +133,12 @@ public override void OnInteract() hasInteracted = true; CloseWindow(); } + + public override bool CanInteract(float distance) + { + if (distance < 5.0f) return true; + else return false; + } // Persistent Coroutine Runner private class CoroutineRunner : MonoBehaviour