Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

이상현상 28(기울어지는 교실 구현) + 교실 전체 box collider 추가 #112

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1102 &-4271778468819435948
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Spinning
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: -8906869970063597199, guid: d735a8aa0bde38e44a13c3a6100fa450, type: 3}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
Expand All @@ -9,4 +35,38 @@ AnimatorController:
m_Name: Banana Animator
serializedVersion: 5
m_AnimatorParameters: []
m_AnimatorLayers: []
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_StateMachine: {fileID: 7127334393053314599}
m_Mask: {fileID: 0}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
m_SyncedLayerIndex: -1
m_DefaultWeight: 0
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1107 &7127334393053314599
AnimatorStateMachine:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: -4271778468819435948}
m_Position: {x: 290, y: 110, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 800, y: 120, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: -4271778468819435948}
9 changes: 4 additions & 5 deletions 302/Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public void Sleep()
{
// 스테이지 클리어한 상태로 잠들기
currentStage++;
// 시계 바늘 업데이트
clockController.SetTime(currentStage);

// 7단계(8:45) 이후 클리어 시 게임 클리어
if (currentStage >= 9)
Expand All @@ -87,9 +85,6 @@ public void Sleep()
// 스테이지 실패 시, 이상현상 리스트를 초기화, 재생성 해야 하므로
// AnomalyManager의 Stage Failure시 작동하는 함수 호출
AnomalyManager.Instance.ResetAnomaliesOnFailure();
// Added by 서 지 희
// 시계 바늘 7:00로 초기화
clockController.SetTime(currentStage);

// Added by 신 채 환
// 슬라이드 색인 배열 재생성
Expand All @@ -104,6 +99,10 @@ public void Sleep()
StartCoroutine(InstantiateAnomalyAfterLoad());
StartCoroutine(FindAndChangeScreen());

// Added by 서 지 희
// LoadDefaultScene() 호출 다음에 시계 조정
clockController.SetTime(currentStage);

// Added by 신 채 환
// 슬라이드 초기화
StartCoroutine(InitializeSlideAfterLoad());
Expand Down
156 changes: 150 additions & 6 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly28Manager.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,162 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Anomaly28Manager : MonoBehaviour
{
// Start is called before the first frame update
private GameManager gameManager;
private GameObject player;

private float tiltMaxAngle = 15f; // Maximum tilt angle for heavy swaying
private float tiltDuration = 5f; // Time for each tilt
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

void Start()
{

// Create a parent GameObject for the classroom
CreateClassroomParent();

// Add rigidbodies to all floatable objects
AddRigidbodiesToFloatables();

// Start the gradual swaying with delay
StartCoroutine(DelayedStartSwaying());

// Stage always clears after experiencing the anomaly
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
gameManager.SetStageClear();

// Find the player object and its Rigidbody
player = GameObject.Find("Player");
if (player != null)
{
playerRb = player.GetComponent<Rigidbody>();
if (playerRb == null)
{
playerRb = player.AddComponent<Rigidbody>(); // Ensure Rigidbody exists
}

// Apply a slight upward force to the player
playerRb.AddForce(Vector3.up * 50f); // Adjust the force as needed
}
}

private void CreateClassroomParent()
{
// Create the parent object
classroomParent = new GameObject("ClassroomParent");

// Find all relevant objects in the scene
GameObject[] objects = {
GameObject.Find("Classroom"),
GameObject.Find("Furniture"),
GameObject.Find("clock"),
GameObject.Find("professor_normal"),
GameObject.Find("Laptop") // 플레이어가 상호작용해야 하는 노트북
};

foreach (GameObject obj in objects)
{
if (obj != null)
{
obj.transform.parent = classroomParent.transform;
}
}
}

private void AddRigidbodiesToFloatables()
{
// Find all objects with the "floatable" tag
GameObject[] floatableObjects = GameObject.FindGameObjectsWithTag(floatableTag);

foreach (GameObject obj in floatableObjects)
{
if (obj.name == "desk (10)") continue; // Skip desk (10) to prevent affecting the laptop

Rigidbody rb = obj.GetComponent<Rigidbody>();
if (rb == null)
{
rb = obj.AddComponent<Rigidbody>();
}

// Enable gravity and set mass
rb.useGravity = true;
rb.mass = 1f; // Adjust mass as needed

// 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()
{
// Wait for 2 seconds before starting the sway
yield return new WaitForSeconds(2f);
StartCoroutine(SwayClassroom());
}

private IEnumerator SwayClassroom()
{
float elapsedTime = 0f;

while (elapsedTime < totalDuration)
{
// Scale tilt magnitude gradually based on elapsed time
float currentMagnitude = Mathf.Lerp(0, tiltMaxAngle, elapsedTime / totalDuration);

// Dynamically tilt along the X-axis
float xTilt = Mathf.Sin(Time.time * (2 * Mathf.PI / tiltDuration)) * currentMagnitude;

// Dynamically tilt along the Z-axis
float zTilt = Mathf.Cos(Time.time * (2 * Mathf.PI / tiltDuration)) * currentMagnitude;

// Apply the rotation to the classroom
classroomParent.transform.rotation = Quaternion.Euler(xTilt, 0, zTilt);

elapsedTime += Time.deltaTime;
yield return null; // Wait for the next frame
}

// Gradually reset to normal
StartCoroutine(GradualReset());
}

private IEnumerator GradualReset()
{
if (classroomParent == null) yield break;

float elapsedTime = 0f;
Quaternion initialRotation = classroomParent.transform.rotation;

while (elapsedTime < tiltDuration)
{
// Gradually reduce the angle back to zero
classroomParent.transform.rotation = Quaternion.Slerp(initialRotation, Quaternion.identity, elapsedTime / tiltDuration);
elapsedTime += Time.deltaTime;
yield return null;
}

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

// Update is called once per frame
void Update()
private void OnCollisionEnter(Collision collision)
{

// Check if the player collides with a "FloorEmpty" tagged object
if (collision.collider.CompareTag(floorEmptyTag) && playerRb != null)
{
// 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!");
}
}
}