diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly22Manager.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly22Manager.cs index 9f0b025..caa22f7 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly22Manager.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly22Manager.cs @@ -7,7 +7,7 @@ public class Anomaly22Manager : MonoBehaviour private GameObject floor; // 모든 타일들의 Parent private GameManager gameManager; private PlayerController playerController; - public float interval = 0.5f; + public float interval = 1f; public float totalSeconds = 30f; private bool isPlayerDead = false; @@ -85,7 +85,7 @@ private IEnumerator AddBoxColliders() { foreach (var tile in floorTiles) { - if (tile != floor.transform) // Skip the parent 'floor' object + if (tile != floor.transform && tile.name != "platform") // Skip the parent 'floor' object { BoxCollider tileCollider = tile.GetComponent(); if (tileCollider == null) @@ -116,7 +116,7 @@ private IEnumerator CountSeconds() void Update() { // 아래로 떨어졌는지 확인해서 Game Over 처리 - if (playerController.transform.position.y < -10f && !isPlayerDead) + if (playerController.transform.position.y < -1f && !isPlayerDead && false) { playerController.Sleep(); isPlayerDead = true; @@ -155,16 +155,47 @@ private IEnumerator TriggerRandomTileShakeAndFallWithInterval() private IEnumerator RestoreAllTiles() { + float duration = 1f; // Duration for the animation (1 second) + float elapsedTime = 0f; + // Store the original positions of all tiles + Dictionary originalPositions = new Dictionary(); foreach (var tile in floorTiles) { + if (tile != floor.transform) // Skip the parent 'floor' object + { + originalPositions[tile] = tile.position; + } + } + + // Animate the tiles back to y = 0 over the duration + while (elapsedTime < duration) + { + elapsedTime += Time.deltaTime; + float t = elapsedTime / duration; // Normalized time [0, 1] + + foreach (var tile in originalPositions.Keys) + { + Vector3 startPos = originalPositions[tile]; + Vector3 targetPos = new Vector3(startPos.x, 0f, startPos.z); + tile.position = Vector3.Lerp(startPos, targetPos, t); + } + + yield return null; // Wait for the next frame + } + + // Ensure all tiles are precisely at y = 0 at the end of the animation + foreach (var tile in originalPositions.Keys) + { + tile.position = new Vector3(tile.position.x, 0f, tile.position.z); + + // Remove the Anomaly22_tile component if it exists Anomaly22_tile tileScript = tile.GetComponent(); if (tileScript != null) { - tileScript.RestoreTile(); + Destroy(tileScript); } - - yield return null; } } + } diff --git a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly22_tile.cs b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly22_tile.cs index 7e88c55..0d21cd4 100644 --- a/302/Assets/Scripts/SpecificAnomalyManager/Anomaly22_tile.cs +++ b/302/Assets/Scripts/SpecificAnomalyManager/Anomaly22_tile.cs @@ -5,83 +5,65 @@ public class Anomaly22_tile : MonoBehaviour { private bool isFalling = false; private bool isRestoring = false; + private Vector3 initialPosition; - // Duration for shaking, falling - public float shakeDuration = 2f; // Duration of shake - public float fallDistance = 15f; // Distance to fall in the Y axis + private float shakeDuration = 2f; + private float fallDistance = 15f; - // Audio properties - private AudioSource audioSource; // The AudioSource to play sounds on the tile - public AudioClip shakeSound; // The sound to play during shaking + [Header("Audio Settings")] + private AudioSource audioSource; + public AudioClip shakeSound; void Awake() { - // Ensure the AudioSource is properly initialized audioSource = GetComponent(); if (audioSource == null) { - // If no AudioSource component, add one audioSource = gameObject.AddComponent(); } } - // Public function to trigger the shake and fall process public void TriggerShakeAndFall() { if (!isFalling && !isRestoring) { - - audioSource.PlayOneShot(shakeSound); // Play the sound once - StartCoroutine(ShakeAndFallRoutine()); + audioSource.PlayOneShot(shakeSound); + StartCoroutine(ShakeAndFallRoutine()); } } - // Coroutine to handle the shaking and falling process private IEnumerator ShakeAndFallRoutine() { isFalling = true; - // Shake in Y-axis for the specified duration float shakeTime = 0f; - Vector3 initialPosition = transform.position; + initialPosition = transform.position; + // shake 단계 while (shakeTime < shakeDuration) { - float shakeAmount = Random.Range(-0.1f, 0.1f); // Adjust the shake amount as needed + float shakeAmount = Random.Range(-0.1f, 0.1f); transform.position = new Vector3(initialPosition.x, initialPosition.y + shakeAmount, initialPosition.z); shakeTime += Time.deltaTime; yield return null; } - // After shaking, reset position to initial (without shake) + // 떨어지는 단계 transform.position = initialPosition; - // Fall down by the specified distance on the Y-axis float fallTime = 0f; Vector3 fallStartPosition = transform.position; Vector3 fallEndPosition = new Vector3(fallStartPosition.x, fallStartPosition.y - fallDistance, fallStartPosition.z); - while (fallTime < 1f) // Smooth fall over 1 second (adjust as needed) + while (fallTime < 1f) { transform.position = Vector3.Lerp(fallStartPosition, fallEndPosition, fallTime); fallTime += Time.deltaTime; yield return null; } - // Ensure final position is exactly at the fall distance transform.position = fallEndPosition; - isFalling = false; } - - // Public function to restore the tile (set Y position to 0) - public void RestoreTile() - { - // Set Y position to 0 - transform.position = new Vector3(transform.position.x, 0f, transform.position.z); - - // Destroy the Anomaly22_tile script after the tile is restored - Destroy(this); // This will remove the Anomaly22_tile script component from the GameObject - } }