Added rumble on screen shake and suck
This commit is contained in:
parent
8ef8b304c0
commit
5ed2045b30
@ -58,6 +58,7 @@ MonoBehaviour:
|
||||
gameFlowManager: {fileID: 0}
|
||||
stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
|
||||
globalCamera: {fileID: 0}
|
||||
screenShaker: {fileID: 0}
|
||||
jumpSource: {fileID: 7164870411903264125}
|
||||
jumpSounds:
|
||||
- {fileID: 8300000, guid: 2f93dc5371f10744ba49e29576e8a6a7, type: 3}
|
||||
@ -104,6 +105,7 @@ MonoBehaviour:
|
||||
- {fileID: 8300000, guid: 4e2519f9a65bd484d95111774c762843, type: 3}
|
||||
playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
|
||||
playerMovement: {fileID: 0}
|
||||
screenShaker: {fileID: 0}
|
||||
--- !u!114 &1967503440015794769
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -145,6 +147,7 @@ MonoBehaviour:
|
||||
suckSource: {fileID: 3555231741827846396}
|
||||
suckSounds:
|
||||
- {fileID: 8300000, guid: c12a57d990960ce44bc7cf4d5f63d32b, type: 3}
|
||||
screenShaker: {fileID: 0}
|
||||
soundManager: {fileID: 0}
|
||||
--- !u!114 &1214567908930553477
|
||||
MonoBehaviour:
|
||||
|
||||
@ -121,10 +121,12 @@ public class BloodSucker : MonoBehaviour {
|
||||
bloodParticles.Play();
|
||||
currentTarget.OnSuck(true);
|
||||
soundManager.PlaySound(suckingSource, suckingSounds, randomPitch: true, createTempSourceIfBusy: false);
|
||||
screenShaker.StartHeldRumble();
|
||||
} else {
|
||||
bloodParticles.Stop(true, ParticleSystemStopBehavior.StopEmitting);
|
||||
if(!(currentTarget is null))currentTarget.OnSuck(false);
|
||||
soundManager.StopSound(suckingSource);
|
||||
screenShaker.StopHeldRumble();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -181,12 +181,12 @@ public class GameFlowManager : MonoBehaviour {
|
||||
gameFlowManager.SetPauseLevel(PauseLevel.PreventActions);
|
||||
}
|
||||
|
||||
public override void LeaveState() => gameFlowManager.startTxt.transform.parent.gameObject.SetActive(false);
|
||||
|
||||
public override BaseState? UpdateState(){
|
||||
gameFlowManager.FadeStartTxt();
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void LeaveState() => gameFlowManager.startTxt.transform.parent.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public class GameplayFlowState : GameFlowState {
|
||||
|
||||
@ -42,6 +42,7 @@ public class PlayerMovement : MonoBehaviour {
|
||||
currentState = new ImmobileMovementState(this);
|
||||
soundManager = FindObjectOfType<SoundManager>();
|
||||
screenShaker = FindObjectOfType<ScreenShaker>();
|
||||
|
||||
}
|
||||
|
||||
void Start() {
|
||||
|
||||
@ -2,29 +2,47 @@ 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;
|
||||
|
||||
void Awake() {
|
||||
cam = GetComponent<CinemachineVirtualCamera>();
|
||||
noise = cam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
}
|
||||
|
||||
public void Shake(float magnitude = 1f, float duration = 0.2f) {
|
||||
StartCoroutine(ShakeCoroutine(magnitude, duration));
|
||||
public void Shake(float magnitude = 1f, float rumbleLowFreq = 0.25f, float rumbleHighFreq = 0.75f, float duration = 0.2f) {
|
||||
if (coroutine is {})
|
||||
StopCoroutine(coroutine);
|
||||
|
||||
coroutine = StartCoroutine(ShakeCoroutine(magnitude, rumbleLowFreq, rumbleHighFreq, duration));
|
||||
}
|
||||
|
||||
IEnumerator ShakeCoroutine(float magnitude, float duration) {
|
||||
public void StartHeldRumble(float rumbleLowFreq = 0.25f, float rumbleHighFreq = 0.75f) {
|
||||
rumbleHeld = true;
|
||||
Gamepad.current.SetMotorSpeeds(rumbleLowFreq, rumbleHighFreq);
|
||||
}
|
||||
|
||||
public void StopHeldRumble() {
|
||||
rumbleHeld = false;
|
||||
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);
|
||||
|
||||
yield return new WaitForSeconds(duration);
|
||||
yield return new WaitForSecondsRealtime(duration);
|
||||
|
||||
noise.m_AmplitudeGain = 0f;
|
||||
noise.m_FrequencyGain = 1f;
|
||||
if (!rumbleHeld)
|
||||
Gamepad.current.ResetHaptics();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user