From b0054d62c6b7450860e5b453539f968aeb1ed45c Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Tue, 1 Nov 2022 12:09:50 +0800 Subject: [PATCH] Create AIPrototype.cs --- TempScriptsFolder/AIPrototype.cs | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 TempScriptsFolder/AIPrototype.cs diff --git a/TempScriptsFolder/AIPrototype.cs b/TempScriptsFolder/AIPrototype.cs new file mode 100644 index 00000000..c7240806 --- /dev/null +++ b/TempScriptsFolder/AIPrototype.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using SHADE; + +public class AIPrototype : Script +{ + //This object's relevant components + private Transform transform; + + [SerializeField] + [Tooltip("The list of waypoints that the object will move around on")] + private Vector3[] waypoints; + + [SerializeField] + [Tooltip("How fast the object moves about waypoints")] + private float moveSpeed; + + //To cycle depending on the length of waypoints + private int currentTargetWaypointIndex; + + public AIPrototype(GameObject gameObj) : base(gameObj) { } + + protected override void awake() + { + transform = GetComponent(); + if (transform == null) + { + Debug.LogError("Transform is NULL!"); + } + + currentTargetWaypointIndex = 0; + } + + protected override void update() + { + //Head towards the next target + transform.GlobalPosition += (waypoints[currentTargetWaypointIndex] - transform.GlobalPosition) * moveSpeed * (float)Time.DeltaTime; + + //Cycle to next waypoint if near enough + if ((waypoints[currentTargetWaypointIndex] - transform.GlobalPosition).GetSqrMagnitude() < 1.0f) + { + ++currentTargetWaypointIndex; + if (currentTargetWaypointIndex == waypoints.Length) + { + currentTargetWaypointIndex = 0; //Recycle + } + } + } +} \ No newline at end of file