diff options
| author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
| commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
| tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /UnitySA.Utility/LerpCtrlBob.cs | |
+init
Diffstat (limited to 'UnitySA.Utility/LerpCtrlBob.cs')
| -rw-r--r-- | UnitySA.Utility/LerpCtrlBob.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/UnitySA.Utility/LerpCtrlBob.cs b/UnitySA.Utility/LerpCtrlBob.cs new file mode 100644 index 0000000..9d23469 --- /dev/null +++ b/UnitySA.Utility/LerpCtrlBob.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections; +using UnityEngine; + +namespace UnitySA.Utility; + +[Serializable] +public class LerpCtrlBob +{ + public float BobDuration; + + public float BobAmount; + + private float m_Offset; + + public float Offset() + { + return m_Offset; + } + + public IEnumerator DoBobCycle() + { + float t2 = 0f; + while (t2 < BobDuration) + { + m_Offset = Mathf.Lerp(0f, BobAmount, t2 / BobDuration); + t2 += Time.deltaTime; + yield return new WaitForFixedUpdate(); + } + t2 = 0f; + while (t2 < BobDuration) + { + m_Offset = Mathf.Lerp(BobAmount, 0f, t2 / BobDuration); + t2 += Time.deltaTime; + yield return new WaitForFixedUpdate(); + } + m_Offset = 0f; + } +} |
