Skip to content

Commit

Permalink
Merge pull request #174 from 2024FALL-SWPP/bugfix/Anomaly28
Browse files Browse the repository at this point in the history
이상현상 28 clock가 DontDestroyOnLand에서 없어지는 문제 해결
  • Loading branch information
seozzi authored Nov 30, 2024
2 parents 849a92c + 28bdd3a commit 4ae7beb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 302/Assets/Scripts/ClockController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class ClockController : MonoBehaviour
{
public static ClockController Instance { get; private set; }
public static ClockController Instance { get; private set; }

private Transform hourHand;
private Transform minuteHand;
Expand Down
49 changes: 47 additions & 2 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly28Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ public class Anomaly28Manager : MonoBehaviour
private float swayDelay = 0.5f; // Time between each sway
private float totalDuration = 15f; // Total duration of the anomaly

private float privatetotalDuration = 15f; // Total duration of the anomaly
private string floatableTag = "floatable"; // Tag to identify floatable objects
private string floorEmptyTag = "FloorEmpty"; // Tag for the floor objects triggering player pop-up

private GameObject classroomParent; // Parent object for the entire classroom
private Rigidbody playerRb; // Rigidbody of the player

// Clock transform variables
private Vector3 initialClockLocalPosition;
private Quaternion initialClockLocalRotation;
private Vector3 originalClockPosition;
private Quaternion originalClockRotation;

void Start()
{
// Create a parent GameObject for the classroom
Expand Down Expand Up @@ -46,6 +51,19 @@ void Start()
// Apply a slight upward force to the player
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;

// 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;
}
}

private void CreateClassroomParent()
Expand All @@ -57,7 +75,6 @@ private void CreateClassroomParent()
GameObject[] objects = {
GameObject.Find("Classroom"),
GameObject.Find("Furniture"),
GameObject.Find("clock"),
GameObject.Find("professor_normal"),
GameObject.Find("Laptop") // 플레이어가 상호작용해야 하는 노트북
};
Expand All @@ -71,6 +88,21 @@ 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 Down Expand Up @@ -159,4 +191,17 @@ private void OnCollisionEnter(Collision collision)
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("Anomaly28Manager destroyed. Clock restored to its original phase.");
}
}

0 comments on commit 4ae7beb

Please sign in to comment.