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.

56 lines
1.3 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using BansheeGz.BGSpline.Components;
  5. using BansheeGz.BGSpline.Curve;
  6. public class Lighthouse : MonoBehaviour
  7. {
  8. public BGCurve splineCurve;
  9. public List<float> splineDistantPoints = new List<float>();
  10. public float speed = 200f;
  11. public float timePadding = 0.5f;
  12. public float timeBetweenPoints = 3f;
  13. private BGCcCursor splineCursor;
  14. private int targetPoint = 0;
  15. private bool reverseDirection = false;
  16. void Start()
  17. {
  18. splineCursor = splineCurve.GetComponent<BGCcCursor>();
  19. moveToNextPoint();
  20. }
  21. public void moveToNextPoint()
  22. {
  23. LeanTween.delayedCall(gameObject, timeBetweenPoints, ()=>{
  24. if (reverseDirection)
  25. targetPoint--;
  26. else
  27. targetPoint++;
  28. if (targetPoint >= splineDistantPoints.Count)
  29. {
  30. if (splineCurve.Closed)
  31. {
  32. targetPoint = 1;
  33. splineCursor.Distance = 0f;
  34. }
  35. else
  36. {
  37. targetPoint = splineDistantPoints.Count - 2;
  38. reverseDirection = !reverseDirection;
  39. }
  40. }
  41. float start = splineCursor.Distance;
  42. float end = splineDistantPoints[targetPoint];
  43. float distance = Mathf.Abs(end - start);
  44. LeanTween.value(gameObject, start, end, distance / speed + timePadding).setOnUpdate((float val)=>{
  45. splineCursor.Distance = val;
  46. }).setEaseInOutQuad().setOnComplete(moveToNextPoint);
  47. });
  48. }
  49. }