using UnityEngine;
using Unity.Cinemachine;

public class CinemachineShake : MonoBehaviour
{
    private CinemachineCamera cmCam;
    private CinemachineBasicMultiChannelPerlin noise;

    private float shakeTimer;

    void Awake()
    {
        cmCam = GetComponent<CinemachineCamera>();
        noise = cmCam.GetComponent<CinemachineBasicMultiChannelPerlin>();
        if (noise == null) Debug.Log("camera found for shaking is null");
    }

    public void Shake(float intensity, float frequency, float duration)
    {
        noise.AmplitudeGain = intensity;
        noise.FrequencyGain = frequency;
        shakeTimer = duration;
    }

    void Update()
    {
        if (shakeTimer > 0)
        {
            shakeTimer -= Time.deltaTime;

            if (shakeTimer <= 0f)
            {
                noise.AmplitudeGain = 0f;
                noise.FrequencyGain = 0f;
            }
        }
    }
}