using System.Collections; using Cinemachine; using UnityEngine; public class CameraShake : MonoBehaviour { public static CameraShake instance; void Start() { if (instance == null) instance = this; } public void ShakeCamera(float intensity, float duration) { StartCoroutine(DoShake(intensity, duration)); print("Shaking da booty"); } private IEnumerator DoShake(float intensity, float duration) { var cam = CinemachineCore.Instance.GetActiveBrain(0).ActiveVirtualCamera.VirtualCameraGameObject.GetComponent(); CinemachineCameraOffset cinemachineCameraOffset = cam.GetComponent(); Vector3 originalOffset = cinemachineCameraOffset.m_Offset; float elapsed = 0.0f; while (elapsed < duration) { float x = Random.Range(-1f, 1f) * intensity; float y = Random.Range(-1f, 1f) * intensity; print("x: " + x + "y: " + y); cam.GetComponent().m_Offset = new Vector3(x, y, originalOffset.z); elapsed += Time.deltaTime; yield return null; } cam.GetComponent().m_Offset = originalOffset; } }