camera shake not working

This commit is contained in:
kimrdd 2024-04-21 07:48:36 +02:00
parent 4504ee8b32
commit 124f95a31d
2 changed files with 51 additions and 0 deletions

View File

@ -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<CinemachineBasicMultiChannelPerlin>();
multiChannelPerlin.m_AmplitudeGain = intensity;
shakeTimer = time;
}
private void Update()
{
if (shakeTimer > 0)
{
shakeTimer -= Time.deltaTime;
if (shakeTimer <= 0f)
{
CinemachineBasicMultiChannelPerlin multiChannelPerlin = v_Camera.GetComponent<CinemachineBasicMultiChannelPerlin>();
multiChannelPerlin.m_AmplitudeGain = 0f;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da54a1d427b68cf40a53acebb823123d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: