summaryrefslogtreecommitdiff
path: root/UnitySA.Utility/LerpCtrlBob.cs
blob: 9d2346952e7714f2c8493c6ee5036c8713d06526 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;
	}
}