1 using System;
2 using
System.Collections;
3 using
UnityEngine;
4
5 namespace
UnityStandardAssets.Utility
6 {
7     
[Serializable]
8     
public class LerpControlledBob
9     {
10         
public float BobDuration;
11         
public float BobAmount;
12
13         
private float m_Offset = 0f;
14
15
16         
// provides the offset that can be used
17         
public float Offset()
18         {
19             
return m_Offset;
20         }
21
22
23         
public IEnumerator DoBobCycle()
24         {
25             
// make the camera move down slightly
26             
float t = 0f;
27             
while (t < BobDuration)
28             {
29                 m_Offset = Mathf.Lerp(
0f, BobAmount, t/BobDuration);
30                 t += Time.deltaTime;
31                 
yield return new WaitForFixedUpdate();
32             }
33
34             
// make it move back to neutral
35             t =
0f;
36             
while (t < BobDuration)
37             {
38                 m_Offset = Mathf.Lerp(BobAmount,
0f, t/BobDuration);
39                 t += Time.deltaTime;
40                 
yield return new WaitForFixedUpdate();
41             }
42             m_Offset =
0f;
43         }
44     }
45 }


Gõ tìm kiếm nhanh...