diff --git a/Assets/CameraShaker.cs b/Assets/CameraShaker.cs new file mode 100644 index 0000000..e3bb773 --- /dev/null +++ b/Assets/CameraShaker.cs @@ -0,0 +1,56 @@ +using System.Collections; +using UnityEngine; +using Cinemachine; // Ensure you have the Cinemachine namespace + +public class CameraShaker : MonoBehaviour +{ + public static CameraShaker Instance; + public CinemachineCameraOffset offsetter; + + // Variables for tracking shake duration and original offset + private Vector3 originalOffset; + private Coroutine shakeCoroutine; + + private void Awake() + { + if (Instance == null) + { + Instance = this; + originalOffset = new Vector3(0, 0, 0); // Initialize with your default offset + } + else + { + Destroy(gameObject); + } + + offsetter = GetComponent(); + } + + public static void ShakecShake(float strength, float time) + { + // Check if a shake is already happening and restart it if so + if (Instance.shakeCoroutine != null) + { + Instance.StopCoroutine(Instance.shakeCoroutine); + } + Instance.shakeCoroutine = Instance.StartCoroutine(Instance.DoShake(strength, time)); + } + + private IEnumerator DoShake(float strength, float time) + { + float elapsed = 0f; + + while (elapsed < time) + { + elapsed += Time.deltaTime; + float x = Random.Range(-1f, 1f) * strength; + float y = Random.Range(-1f, 1f) * strength; + + offsetter.m_Offset = new Vector3(x, y, originalOffset.z); + yield return null; // Wait for the next frame + } + + // Reset the offset to the original position + offsetter.m_Offset = originalOffset; + } +} diff --git a/Assets/CameraShaker.cs.meta b/Assets/CameraShaker.cs.meta new file mode 100644 index 0000000..674cfec --- /dev/null +++ b/Assets/CameraShaker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ea81d9be44682764ba43ffdbef0ef976 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/CameraRig.prefab b/Assets/Prefabs/CameraRig.prefab index 2e83e06..ba9821d 100644 --- a/Assets/Prefabs/CameraRig.prefab +++ b/Assets/Prefabs/CameraRig.prefab @@ -197,6 +197,7 @@ MonoBehaviour: - {fileID: 0} - {fileID: 0} initialSpawnDelay: 5 + timer: 0 enemyList: [] --- !u!114 &7140252695900592518 MonoBehaviour: @@ -323,6 +324,8 @@ GameObject: - component: {fileID: 3197454023887695364} - component: {fileID: 1945378220081163713} - component: {fileID: 4060518028321021500} + - component: {fileID: 6479560527566926107} + - component: {fileID: 4203055092890111090} m_Layer: 0 m_Name: Virtual Camera m_TagString: Untagged @@ -399,6 +402,34 @@ MonoBehaviour: m_EditorClassIdentifier: MinPitch: 0 MaxPitch: 0 +--- !u!114 &6479560527566926107 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6306269600238927148} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 44d70cc20219cd84593f67d248eafe36, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Offset: {x: 0, y: 0, z: 0} + m_ApplyAfter: 1 + m_PreserveComposition: 0 +--- !u!114 &4203055092890111090 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6306269600238927148} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ea81d9be44682764ba43ffdbef0ef976, type: 3} + m_Name: + m_EditorClassIdentifier: + offsetter: {fileID: 0} --- !u!1 &6455280833853463581 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 8bc79c0..e8b6310 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -529,6 +529,50 @@ Transform: m_CorrespondingSourceObject: {fileID: 3862814901187971034, guid: 5846f4d0fc6a1a44ba388893e7ff9373, type: 3} m_PrefabInstance: {fileID: 7693964683212020007} m_PrefabAsset: {fileID: 0} +--- !u!1 &690229187 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 6306269600238927148, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + m_PrefabInstance: {fileID: 5796191506433166633} + m_PrefabAsset: {fileID: 0} +--- !u!114 &690229190 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 1945378220081163713, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + m_PrefabInstance: {fileID: 5796191506433166633} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 690229187} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 45e653bab7fb20e499bda25e1b646fea, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &690229191 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 690229187} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ea81d9be44682764ba43ffdbef0ef976, type: 3} + m_Name: + m_EditorClassIdentifier: + cinemachineVirtualCamera: {fileID: 690229190} +--- !u!114 &690229192 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 690229187} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 44d70cc20219cd84593f67d248eafe36, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Offset: {x: 0, y: 0, z: 0} + m_ApplyAfter: 1 + m_PreserveComposition: 0 --- !u!1 &708735388 GameObject: m_ObjectHideFlags: 0 @@ -8740,7 +8784,13 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 6306269600238927148, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + insertIndex: -1 + addedObject: {fileID: 690229192} + - targetCorrespondingSourceObject: {fileID: 6306269600238927148, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + insertIndex: -1 + addedObject: {fileID: 690229191} m_SourcePrefab: {fileID: 100100000, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} --- !u!114 &5796191506433166634 stripped MonoBehaviour: diff --git a/Assets/Scripts/Enemy/EnemyPathFinding.cs b/Assets/Scripts/Enemy/EnemyPathFinding.cs index 6e124ee..fac8016 100644 --- a/Assets/Scripts/Enemy/EnemyPathFinding.cs +++ b/Assets/Scripts/Enemy/EnemyPathFinding.cs @@ -28,6 +28,7 @@ public class EnemyPathFinding : MonoBehaviour private void Rumble() { RumbleManager.StartRumble(-1, 0.5f, 0.5f, 0.25f); + CameraShaker.ShakecShake(0.125f, 0.25f); } private void Update()