69 lines
1.3 KiB
C#
69 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ShipMover : MonoBehaviour
|
|
{
|
|
public class Waypoint
|
|
{
|
|
public float standTime;
|
|
|
|
public bool useItsRotation;
|
|
|
|
public LeanTweenType tweenType = LeanTweenType.linear;
|
|
}
|
|
|
|
public GameObject objectToMove;
|
|
|
|
public float speed = 1f;
|
|
|
|
public bool loopClamp;
|
|
|
|
public bool loopPingPong;
|
|
|
|
public LeanTweenType easeType = LeanTweenType.linear;
|
|
|
|
public bool orientToPath;
|
|
|
|
public List<GameObject> waypoints = new List<GameObject>();
|
|
|
|
[HideInInspector]
|
|
public Vector3[] tweenPoints;
|
|
|
|
[HideInInspector]
|
|
public int tweenId = -1;
|
|
|
|
public LTDescr tween;
|
|
|
|
public void Start()
|
|
{
|
|
if (objectToMove == null)
|
|
{
|
|
objectToMove = base.gameObject;
|
|
}
|
|
tweenPoints = new Vector3[waypoints.Count];
|
|
for (int i = 0; i < waypoints.Count; i++)
|
|
{
|
|
tweenPoints[i] = waypoints[i].transform.position;
|
|
}
|
|
tween = LeanTween.moveSpline(objectToMove, tweenPoints, PathDistance() / speed).setEase(easeType).setOrientToPath(orientToPath);
|
|
if (loopClamp)
|
|
{
|
|
tween.setLoopClamp();
|
|
}
|
|
else if (loopPingPong)
|
|
{
|
|
tween.setLoopPingPong();
|
|
}
|
|
}
|
|
|
|
public float PathDistance()
|
|
{
|
|
float num = 0f;
|
|
for (int i = 1; i < tweenPoints.Length - 2; i++)
|
|
{
|
|
num += Vector3.Distance(tweenPoints[i], tweenPoints[i + 1]);
|
|
}
|
|
return num;
|
|
}
|
|
}
|