From f4ee5d0de18a9021d34edcb6e189ef5e2be8666a Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 20:06:24 -0400 Subject: [PATCH] Can get attack rumble while sucking? --- Assets/Scripts/ScreenShaker.cs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) 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(); } - }