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.

47 lines
1.1 KiB

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