From ff36e75f9e4e079c98f44b963965a1580d7252d6 Mon Sep 17 00:00:00 2001 From: seozzi Date: Sun, 15 Dec 2024 18:32:56 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=83=81=ED=98=84=EC=83=81=2028=20ref?= =?UTF-8?q?actoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Anomaly28Controller.cs | 66 ++++++------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly28Controller.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly28Controller.cs index d04407c..7bd7296 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly28Controller.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly28Controller.cs @@ -25,8 +25,10 @@ public class Anomaly28Controller : AbstractAnomalyObject private Vector3 originalClockPosition; private Quaternion originalClockRotation; - void Start() + public override bool StartAnomaly() { + bool res = base.StartAnomaly(); + // Create a parent GameObject for the classroom CreateClassroomParent(); @@ -54,18 +56,22 @@ void Start() playerRb.AddForce(Vector3.up * 50f); // Adjust the force as needed } - // Handle clock separately - GameObject clock = GameObject.Find("clock"); - if (clock != null && classroomParent != null) - { - // Save the clock's original global position and rotation - originalClockPosition = clock.transform.position; - originalClockRotation = clock.transform.rotation; + return res; + } - // Calculate and store the initial local position and rotation relative to the classroomParent - initialClockLocalPosition = clock.transform.position - classroomParent.transform.position; - initialClockLocalRotation = Quaternion.Inverse(classroomParent.transform.rotation) * clock.transform.rotation; - } + // 이상현상을 초기화하는 메서드 + public override bool ResetAnomaly() + { + bool res = base.ResetAnomaly(); + + StartCoroutine(GradualReset()); + + return res; + } + + private void Start() + { + StartAnomaly(); } private void CreateClassroomParent() @@ -77,6 +83,7 @@ private void CreateClassroomParent() GameObject[] objects = { GameObject.Find("Classroom"), GameObject.Find("Furniture"), + GameObject.Find("clock"), GameObject.Find("professor_normal"), GameObject.Find("Laptop") // 플레이어가 상호작용해야 하는 노트북 }; @@ -90,21 +97,6 @@ private void CreateClassroomParent() } } - void Update() - { - GameObject clock = GameObject.Find("clock"); - if (clock != null && classroomParent != null) - { - // Calculate the new global position and rotation using the stored initial local values - Vector3 newClockPosition = classroomParent.transform.TransformPoint(initialClockLocalPosition); - Quaternion newClockRotation = classroomParent.transform.rotation * initialClockLocalRotation; - - // Update clock's transform - clock.transform.position = newClockPosition; - clock.transform.rotation = newClockRotation; - } - } - private void AddRigidbodiesToFloatables() { // Find all objects with the "floatable" tag @@ -127,8 +119,6 @@ private void AddRigidbodiesToFloatables() // Apply a slight upward force to prevent them from sinking into the floor rb.AddForce(Vector3.up * 2f, ForceMode.Impulse); // Adjust the force as needed } - - Debug.Log("Rigidbodies added and upward forces applied to all floatable objects."); } private IEnumerator DelayedStartSwaying() @@ -160,8 +150,7 @@ private IEnumerator SwayClassroom() yield return null; // Wait for the next frame } - // Gradually reset to normal - StartCoroutine(GradualReset()); + ResetAnomaly(); } private IEnumerator GradualReset() @@ -180,7 +169,6 @@ private IEnumerator GradualReset() } classroomParent.transform.rotation = Quaternion.identity; - Debug.Log("Classroom reset to normal."); } private void OnCollisionEnter(Collision collision) @@ -190,20 +178,6 @@ private void OnCollisionEnter(Collision collision) { // Apply a slight upward force to the player playerRb.AddForce(Vector3.up * 200f); // Adjust the force as needed - Debug.Log("Player popped up after colliding with FloorEmpty!"); } } - - void OnDestroy() - { - GameObject clock = GameObject.Find("clock"); - if (clock != null) - { - // Restore the clock's original global position and rotation - clock.transform.position = originalClockPosition; - clock.transform.rotation = originalClockRotation; - } - - Debug.Log("Anomaly28Controller destroyed. Clock restored to its original phase."); - } }