Advertisement
talmud

lerp cycle

Nov 23rd, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class LerpCycle : MonoBehaviour {
  6.  
  7. public Transform start;
  8. public Transform end;
  9. public float frequency;
  10.  
  11.  
  12. // Use this for initialization
  13. IEnumerator Start () {
  14.  
  15. float startTime = Time.time;
  16.  
  17. while (true)
  18. {
  19. float cycle = Mathf.Sin(frequency * Time.time); // -1 to 1
  20. cycle += 1; // 0 to 2
  21. cycle /= 2; // 0 to 1
  22.  
  23. transform.position = Vector3.Lerp(start.position, end.position, cycle);
  24. yield return null;
  25. }
  26.  
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement