You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

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