Skip to content

Commit

Permalink
이상현상 28 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
seozzi committed Dec 15, 2024
1 parent ba8f0fd commit ff36e75
Showing 1 changed file with 20 additions and 46 deletions.
66 changes: 20 additions & 46 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly28Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand All @@ -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") // 플레이어가 상호작용해야 하는 노트북
};
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -180,7 +169,6 @@ private IEnumerator GradualReset()
}

classroomParent.transform.rotation = Quaternion.identity;
Debug.Log("Classroom reset to normal.");
}

private void OnCollisionEnter(Collision collision)
Expand All @@ -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.");
}
}

0 comments on commit ff36e75

Please sign in to comment.