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.

46 lines
1.3 KiB

7 years ago
  1. using UnityEngine;
  2. using System.Collections;
  3. using DentedPixel;
  4. public class PathSplines : MonoBehaviour {
  5. public Transform[] trans;
  6. LTSpline cr;
  7. private GameObject avatar1;
  8. void OnEnable(){
  9. // create the path
  10. cr = new LTSpline( new Vector3[] {trans[0].position, trans[1].position, trans[2].position, trans[3].position, trans[4].position} );
  11. // cr = new LTSpline( new Vector3[] {new Vector3(-1f,0f,0f), new Vector3(0f,0f,0f), new Vector3(4f,0f,0f), new Vector3(20f,0f,0f), new Vector3(30f,0f,0f)} );
  12. }
  13. void Start () {
  14. avatar1 = GameObject.Find("Avatar1");
  15. // Tween automatically
  16. LeanTween.move(avatar1, cr, 6.5f).setOrientToPath(true).setRepeat(1).setOnComplete( ()=>{
  17. Vector3[] next = new Vector3[] {trans[4].position, trans[3].position, trans[2].position, trans[1].position, trans[0].position};
  18. LeanTween.moveSpline( avatar1, next, 6.5f); // move it back to the start without an LTSpline
  19. }).setEase(LeanTweenType.easeOutQuad);
  20. }
  21. private float iter;
  22. void Update () {
  23. // Or Update Manually
  24. // cr.place( avatar1.transform, iter );
  25. iter += Time.deltaTime*0.07f;
  26. if(iter>1.0f)
  27. iter = 0.0f;
  28. }
  29. void OnDrawGizmos(){
  30. // Debug.Log("drwaing");
  31. if(cr==null)
  32. OnEnable();
  33. Gizmos.color = Color.red;
  34. if(cr!=null)
  35. cr.gizmoDraw(); // To Visualize the path, use this method
  36. }
  37. }