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<float> splineDistantPoints = new List<float>();
|
|
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<BGCcCursor>();
|
|
|
|
moveToNextPoint();
|
|
}
|
|
|
|
public void moveToNextPoint()
|
|
{
|
|
LeanTween.delayedCall(gameObject, timeBetweenPoints, ()=>{
|
|
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);
|
|
});
|
|
}
|
|
}
|