diff --git a/Assets/Scripts/ScreenShaker.cs b/Assets/Scripts/ScreenShaker.cs index a84d72b..188e698 100644 --- a/Assets/Scripts/ScreenShaker.cs +++ b/Assets/Scripts/ScreenShaker.cs @@ -1,14 +1,14 @@ +#nullable enable using System.Collections; -using System.Collections.Generic; using UnityEngine; using Cinemachine; using UnityEngine.InputSystem; public class ScreenShaker : MonoBehaviour { - CinemachineVirtualCamera cam; - CinemachineBasicMultiChannelPerlin noise; - Coroutine coroutine; - bool rumbleHeld; + CinemachineVirtualCamera cam = null!; + CinemachineBasicMultiChannelPerlin noise = null!; + Coroutine? coroutine; + (float, float)? heldRumble; void Awake() { cam = GetComponent(); @@ -23,26 +23,27 @@ public class ScreenShaker : MonoBehaviour { } public void StartHeldRumble(float rumbleLowFreq = 0.25f, float rumbleHighFreq = 0.75f) { - rumbleHeld = true; + heldRumble = (rumbleLowFreq, rumbleHighFreq); Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq); } public void StopHeldRumble() { - rumbleHeld = false; + heldRumble = null; Gamepad.current.ResetHaptics(); } IEnumerator ShakeCoroutine(float magnitude, float rumbleLowFreq, float rumbleHighFreq, float duration) { noise.m_AmplitudeGain = magnitude; noise.m_FrequencyGain = 10f; - Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq); + Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq); yield return new WaitForSecondsRealtime(duration); noise.m_AmplitudeGain = 0f; noise.m_FrequencyGain = 1f; - if (!rumbleHeld) - Gamepad.current.ResetHaptics(); + if (heldRumble != null) + Gamepad.current.SetMotorSpeeds(heldRumble.Value.Item1, heldRumble.Value.Item2); + else + Gamepad.current.ResetHaptics(); } - }