From 32ed51ea4697fdaf920abb41c8a25ddbf4c0d0a0 Mon Sep 17 00:00:00 2001 From: mikeleo03 <leonmichael463@gmail.com> Date: Mon, 29 Apr 2024 17:05:57 +0700 Subject: [PATCH] feat ; countdown on game over --- Assets/Animation/GameOverClip.anim | 72 +++---- Assets/Scenes/Main.unity | 181 +++++++++--------- Assets/Scripts/Managers/CountdownManager.cs | 56 ++++++ .../Scripts/Managers/CountdownManager.cs.meta | 11 ++ Assets/Scripts/Managers/GameOverManager.cs | 8 +- 5 files changed, 182 insertions(+), 146 deletions(-) create mode 100644 Assets/Scripts/Managers/CountdownManager.cs create mode 100644 Assets/Scripts/Managers/CountdownManager.cs.meta diff --git a/Assets/Animation/GameOverClip.anim b/Assets/Animation/GameOverClip.anim index 1aacbaf..442edbd 100644 --- a/Assets/Animation/GameOverClip.anim +++ b/Assets/Animation/GameOverClip.anim @@ -88,7 +88,7 @@ AnimationClip: inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - serializedVersion: 3 - time: 1.0333333 + time: 0.73333335 value: {x: 1, y: 1, z: 1} inSlope: {x: 0, y: 0, z: 0} outSlope: {x: 0, y: 0, z: 0} @@ -356,7 +356,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 0 + value: 70 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -364,17 +364,17 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.5 - value: -47.1 - inSlope: -43.000004 - outSlope: -43.000004 + time: 0.2 + value: 70 + inSlope: 0 + outSlope: 0 tangentMode: 136 weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 1.2 - value: -60 + time: 0.95 + value: 15 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -402,15 +402,6 @@ AnimationClip: weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334 - - serializedVersion: 3 - time: 0.5 - value: -1 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 @@ -616,15 +607,6 @@ AnimationClip: isPPtrCurve: 0 isIntCurve: 0 isSerializeReferenceCurve: 0 - - serializedVersion: 2 - path: 459710920 - attribute: 1460864421 - script: {fileID: 0} - typeID: 224 - customType: 28 - isPPtrCurve: 0 - isIntCurve: 0 - isSerializeReferenceCurve: 0 - serializedVersion: 2 path: 2376362178 attribute: 3305885265 @@ -679,6 +661,15 @@ AnimationClip: isPPtrCurve: 0 isIntCurve: 0 isSerializeReferenceCurve: 0 + - serializedVersion: 2 + path: 459710920 + attribute: 1460864421 + script: {fileID: 0} + typeID: 224 + customType: 28 + isPPtrCurve: 0 + isIntCurve: 0 + isSerializeReferenceCurve: 0 pptrCurveMapping: [] m_AnimationClipSettings: serializedVersion: 2 @@ -1154,7 +1145,7 @@ AnimationClip: m_Curve: - serializedVersion: 3 time: 0 - value: 0 + value: 70 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -1162,17 +1153,17 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.5 - value: -47.1 - inSlope: -43.000004 - outSlope: -43.000004 + time: 0.2 + value: 70 + inSlope: 0 + outSlope: 0 tangentMode: 136 weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 1.2 - value: -60 + time: 0.95 + value: 15 inSlope: 0 outSlope: 0 tangentMode: 136 @@ -1200,15 +1191,6 @@ AnimationClip: weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334 - - serializedVersion: 3 - time: 0.5 - value: -1 - inSlope: 0 - outSlope: 0 - tangentMode: 136 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 @@ -1309,7 +1291,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 1.0333333 + time: 0.73333335 value: 1 inSlope: 0 outSlope: 0 @@ -1348,7 +1330,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 1.0333333 + time: 0.73333335 value: 1 inSlope: 0 outSlope: 0 @@ -1387,7 +1369,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 1.0333333 + time: 0.73333335 value: 1 inSlope: 0 outSlope: 0 diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index d3b6e45..2ade80f 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -2246,7 +2246,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 70} m_SizeDelta: {x: 130, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &1139190131 @@ -2329,7 +2329,6 @@ RectTransform: - {fileID: 1664263448} - {fileID: 1434159494} - {fileID: 1394906874} - - {fileID: 1575011244} - {fileID: 1878018288} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -2363,6 +2362,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: timerManager: {fileID: 1878018289} + countdownManager: {fileID: 1664263451} restartDelay: 10 --- !u!95 &1139190137 Animator: @@ -2866,7 +2866,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -76.0889, y: -35} + m_AnchoredPosition: {x: -89, y: -35} m_SizeDelta: {x: 128.17773, y: 52.2159} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1434159495 @@ -2923,98 +2923,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b4f43bf66218c874d871d02802b6a2db, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!1 &1575011243 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1575011244} - - component: {fileID: 1575011248} - - component: {fileID: 1575011247} - - component: {fileID: 1575011245} - m_Layer: 5 - m_Name: GrenadeText - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &1575011244 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1575011243} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 1139190134} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0} - m_AnchorMax: {x: 0.5, y: 0} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 200, y: 60} - m_Pivot: {x: 0.5, y: 0} ---- !u!114 &1575011245 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1575011243} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1e0abf995d32749428603ba20a9d41fc, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!114 &1575011247 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1575011243} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 0.784} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_FontData: - m_Font: {fileID: 12800000, guid: 46238fb1ad7a7a84ba8954c1c860994c, type: 3} - m_FontSize: 32 - m_FontStyle: 0 - m_BestFit: 0 - m_MinSize: 0 - m_MaxSize: 50 - m_Alignment: 4 - m_AlignByGeometry: 0 - m_RichText: 1 - m_HorizontalOverflow: 1 - m_VerticalOverflow: 0 - m_LineSpacing: 1 - m_Text: 'Grenades: 0' ---- !u!222 &1575011248 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1575011243} - m_CullTransparentMesh: 1 --- !u!1001 &1641232233 PrefabInstance: m_ObjectHideFlags: 0 @@ -3023,6 +2931,74 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 400002, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 400002, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalScale.x + value: 1.0000001 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalScale.y + value: 1.0000001 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalScale.z + value: 0.99999994 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalPosition.x + value: 0.28490835 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalPosition.y + value: 0.29675734 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalPosition.z + value: 0.71900976 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalRotation.w + value: 0.99999976 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalRotation.x + value: 0.000680983 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 400004, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} - target: {fileID: 400006, guid: 4e5a0d387dc27394b81600988ad0216f, type: 3} propertyPath: m_RootOrder value: 1 @@ -3209,6 +3185,7 @@ GameObject: - component: {fileID: 1664263448} - component: {fileID: 1664263450} - component: {fileID: 1664263449} + - component: {fileID: 1664263451} m_Layer: 5 m_Name: CountdownText m_TagString: Untagged @@ -3277,6 +3254,20 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1664263447} m_CullTransparentMesh: 1 +--- !u!114 &1664263451 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1664263447} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c7b6e7c3c78b01d4eb3cc6223c46fc2f, type: 3} + m_Name: + m_EditorClassIdentifier: + countdownTime: 10 + countdownDisplay: {fileID: 1664263449} --- !u!1 &1712414649 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Managers/CountdownManager.cs b/Assets/Scripts/Managers/CountdownManager.cs new file mode 100644 index 0000000..7078eee --- /dev/null +++ b/Assets/Scripts/Managers/CountdownManager.cs @@ -0,0 +1,56 @@ +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.SceneManagement; +using System.Collections; + +public class CountdownManager : MonoBehaviour { + + public int countdownTime; + public Text countdownDisplay; + private bool isRunning = false; + private Coroutine countdownCoroutine; + + // Start the countdown coroutine if it's set to start automatically + void Start() { + if (isRunning) { + StartCountdown(); + } + } + + private IEnumerator CountdownToStart() { + while (countdownTime > 0) { + countdownDisplay.text = countdownTime.ToString(); + yield return new WaitForSeconds(1); + countdownTime--; + } + + countdownDisplay.text = "0"; + StopCountdown(); + LoadMenuScene(); + ResetCountdown(); + } + + private void LoadMenuScene() { + SceneManager.LoadScene("Menu"); + } + + public void ResetCountdown() { + countdownTime = 10; + } + + public void StartCountdown() { + if (!isRunning) { + isRunning = true; + countdownCoroutine = StartCoroutine(CountdownToStart()); + } + } + + public void StopCountdown() { + if (isRunning) { + isRunning = false; + if (countdownCoroutine != null) { + StopCoroutine(countdownCoroutine); + } + } + } +} diff --git a/Assets/Scripts/Managers/CountdownManager.cs.meta b/Assets/Scripts/Managers/CountdownManager.cs.meta new file mode 100644 index 0000000..2765379 --- /dev/null +++ b/Assets/Scripts/Managers/CountdownManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c7b6e7c3c78b01d4eb3cc6223c46fc2f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Managers/GameOverManager.cs b/Assets/Scripts/Managers/GameOverManager.cs index d5564ca..1c52e7c 100644 --- a/Assets/Scripts/Managers/GameOverManager.cs +++ b/Assets/Scripts/Managers/GameOverManager.cs @@ -7,6 +7,7 @@ namespace Nightmare { public class GameOverManager : MonoBehaviour { private PlayerHealth playerHealth; [SerializeField] private TimerManager timerManager; + [SerializeField] private CountdownManager countdownManager; Animator anim; LevelManager lm; @@ -22,12 +23,7 @@ namespace Nightmare { void Update() { if (playerHealth.currentHealth <= 0) { anim.SetTrigger("GameOver"); - restartTimer += Time.deltaTime; - - if (restartTimer >= restartDelay) { - SceneManager.LoadScene("Menu"); - anim.SetBool("GameOver", false); - } + countdownManager.StartCountdown(); } } -- GitLab