-1

i have done some code to allow my capsule to move from waypoint to waypoint and unity isn't picking up that exists enter image description here

and here is the code my emptybody is called WayPoints all children are called Waypoint through to Waypoint(13)

public class WayPoints : MonoBehaviour
{
    public static Transform[] points;

    void Awake ()
        {
            points = new Transform[transform.childCount];
            for (int i = 0; i < points.Length; i++)
                {
                    points[i] = transform.GetChild(i);
                }
        }
}

Edit: after changing to list is now coming up with error enter image description here

new code:

public class Enemy : MonoBehaviour
{
        public float speed = 10f;
        public static List<Vector3[]> points = new List<Vector3>();

        private Transform target;
        private int wavepointIndex = 0;

        void start ()
            {
                target = WayPoints.points[0];
            }

void Awake ()
    {
        points = new List<Vector3>();
        for (int i = 0; i < transform.childCount; i++)
            {
                points[i] = transform.GetChild(i).position;
            }
    }

}
  • Code provides doesn’t match error. – BugFinder May 12 '22 at 14:54
  • **TYPO!**: You have `void start ()` instead of `void Start()` so Unity will not find it and not call it => `target` is never assigned ... you didn't show us the affected code btw which would be in `Update` within the `Enemy` component ... – derHugo May 12 '22 at 15:53

1 Answers1

-1

I don't have access to Unity to test but reading your code I would alter to work with an array or list of Vector3 objects.

Something along the lines of (not tested)

public static List<Vector3[]> points = new List<Vector3>();

    void Awake ()
        {
            points = new List<Vector3>();
            for (int i = 0; i < transform.childCount; i++)
                {
                    points[i] = transform.GetChild(i).position;
                }
        }