参考
2019-03-15 【UnityTips】【曲线】 CameraShake.cs 带曲线操作的相机小恶魔
作者:持刀的要迟到了
链接
using UnityEngine;
public class CameraShake : MonoBehaviour
{
private static CameraShake m_this = null;
public static CameraShake Instance
{
get
{
return m_this;
}
}
void Awake()
{
m_this = this;
}
public float effectTime;
private bool startShake = false;
private float seconds = 0f;
public AnimationCurve shakeQuake;
public void Play()
{
seconds = 0;
startShake = true;
}
//private void Update()
//{
// if (Input.GetKeyDown(KeyCode.A))
// {
// seconds = 0;
// startShake = true;
// }
//}
void LateUpdate()
{
if (!startShake)
{
return;
}
seconds += Time.deltaTime;
float nPct = seconds / effectTime;
transform.localPosition = Random.insideUnitSphere * shakeQuake.Evaluate(nPct);
if (nPct >= 1)
{
transform.localPosition = Vector3.zero;
startShake = false;
}
}
}
程序学无止尽。
欢迎大家沟通,有啥不明确的,或者不对的,也可以和我私聊
我的QQ 334524067 神一般的狄狄