The path script

Here is our Path.cs script, which is responsible for managing our waypoints:

using UnityEngine;public class Path: MonoBehaviour{    [SerializeField]    private Vector3[] waypoints;    public bool isDebug = true;    public float radius = 2.0f;    public float PathLength {        get { return waypoints.Length; }    }        public Vector3 GetPoint(int index)    {        return waypoints[index];    }        private void OnDrawGizmos()    {        if (!isDebug) {            return;        }        for (int i = 0; i < waypoints.Length; i++)        {            if (i + 1 < waypoints.Length)            {                Debug.DrawLine(waypoints[i], waypoints[i + 1], Color.red);            }        }    }}
The SerializeField property can be used to force Unity to serialize a private field, and display it in the inspector.

Our waypoints' Vector3 array is the collection of waypoints ...

Get Unity 2017 Game AI Programming - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.