diff options
author | chai <215380520@qq.com> | 2023-11-25 18:39:02 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-11-25 18:39:02 +0800 |
commit | 0e63c4a2c6dec8dfa260501fb7d73750261ea7b7 (patch) | |
tree | f6f2291be65d195d6082b523a56183c332715240 /Assembly_CSharp/Waypoint.cs |
+ init
Diffstat (limited to 'Assembly_CSharp/Waypoint.cs')
-rw-r--r-- | Assembly_CSharp/Waypoint.cs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Assembly_CSharp/Waypoint.cs b/Assembly_CSharp/Waypoint.cs new file mode 100644 index 0000000..b250079 --- /dev/null +++ b/Assembly_CSharp/Waypoint.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using UnityEngine; + +public class Waypoint : MonoBehaviour +{ + [SerializeField] + private Waypoint next; + + [SerializeField] + private List<Waypoint> previous = new List<Waypoint>(); + + public float distanceFromEnd; + + public bool trueDistance; + + private void Start() + { + UpdateDistance(); + } + + public Waypoint GetNextWaypoint() + { + if (next != null) + { + return next; + } + return this; + } + + public void SetNextWaypoint(Waypoint newNext) + { + next = newNext; + } + + public void AddPreviousWaypoint(Waypoint previousWaypoint) + { + previous.Add(previousWaypoint); + } + + public Waypoint[] GetPreviousWaypoints() + { + return previous.ToArray(); + } + + public void UpdateDistance() + { + if (next == null) + { + trueDistance = true; + return; + } + if (!next.trueDistance) + { + next.UpdateDistance(); + } + if (!trueDistance) + { + distanceFromEnd = next.distanceFromEnd + Vector3.Magnitude(next.transform.position - base.transform.position); + trueDistance = true; + } + } +} |