init
This commit is contained in:
commit
102013b228
1443 changed files with 1065651 additions and 0 deletions
45
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs
Normal file
45
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class ScreenShakeCall : MonoBehaviour{
|
||||
|
||||
[SerializeField] bool orbitalCamera = false;
|
||||
CinemachineFreeLook freeLook;
|
||||
CinemachineVirtualCamera vCam;
|
||||
float shakeTimer;
|
||||
float shakeTimerTotal;
|
||||
float startingIntensity;
|
||||
|
||||
public static ScreenShakeCall instance { get; private set; }
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
vCam = GetComponent<CinemachineVirtualCamera>();
|
||||
freeLook = GetComponent<CinemachineFreeLook>();
|
||||
}
|
||||
|
||||
/// <summary> Smoothly shakes with a certain intensity and duration </summary>
|
||||
public void ShakeCamera(float intensity, float time){
|
||||
startingIntensity = intensity;
|
||||
shakeTimer = shakeTimerTotal = time;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (shakeTimer > 0){
|
||||
shakeTimer -= Time.deltaTime;
|
||||
if (orbitalCamera){
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin1 = freeLook.GetRig(0).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin2 = freeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin3 = freeLook.GetRig(2).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
multiChannelPerlin1.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
multiChannelPerlin2.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
multiChannelPerlin3.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
}else{
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin = vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
multiChannelPerlin.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue