diff --git a/Assets/Scripts/Camera/CameraShake.cs b/Assets/Scripts/Camera/CameraShake.cs new file mode 100644 index 0000000..8345514 --- /dev/null +++ b/Assets/Scripts/Camera/CameraShake.cs @@ -0,0 +1,40 @@ +using Cinemachine; +using UnityEngine; + +public class CameraShake : MonoBehaviour +{ + [SerializeField]private CinemachineFreeLook v_Camera; + private float shakeTimer; + + public static CameraShake Instance; + + private void Start() + { + if (Instance != this) + Destroy(Instance); + Instance = this; + } + + public void ShakeCamera(float intensity, float time) + { + CinemachineBasicMultiChannelPerlin multiChannelPerlin = v_Camera.GetComponent(); + + multiChannelPerlin.m_AmplitudeGain = intensity; + shakeTimer = time; + } + + private void Update() + { + if (shakeTimer > 0) + { + shakeTimer -= Time.deltaTime; + if (shakeTimer <= 0f) + { + CinemachineBasicMultiChannelPerlin multiChannelPerlin = v_Camera.GetComponent(); + + multiChannelPerlin.m_AmplitudeGain = 0f; + + } + } + } +} diff --git a/Assets/Scripts/Camera/CameraShake.cs.meta b/Assets/Scripts/Camera/CameraShake.cs.meta new file mode 100644 index 0000000..85fcbb9 --- /dev/null +++ b/Assets/Scripts/Camera/CameraShake.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: da54a1d427b68cf40a53acebb823123d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: