camera shake not working
This commit is contained in:
parent
4504ee8b32
commit
124f95a31d
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: da54a1d427b68cf40a53acebb823123d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue