using System.Collections; using System.Collections.Generic; using UnityEngine; using BansheeGz.BGSpline.Components; using BansheeGz.BGSpline.Curve; public class Lighthouse : MonoBehaviour { public BGCurve splineCurve; public List splineDistantPoints = new List(); public float speed = 200f; public float timePadding = 0.5f; public float timeBetweenPoints = 3f; private BGCcCursor splineCursor; private int targetPoint = 0; private bool reverseDirection = false; void Start() { splineCursor = splineCurve.GetComponent(); if (splineDistantPoints == null || splineDistantPoints.Count == 0) { splineDistantPoints.Add(0f); for (int i=1; i{ if (reverseDirection) targetPoint--; else targetPoint++; if (targetPoint >= splineDistantPoints.Count) { if (splineCurve.Closed) { targetPoint = 1; splineCursor.Distance = 0f; } else { targetPoint = splineDistantPoints.Count - 2; reverseDirection = !reverseDirection; } } float start = splineCursor.Distance; float end = splineDistantPoints[targetPoint]; float distance = Mathf.Abs(end - start); LeanTween.value(gameObject, start, end, distance / speed + timePadding).setOnUpdate((float val)=>{ splineCursor.Distance = val; }).setEaseInOutQuad().setOnComplete(moveToNextPoint); }); } }