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