Look very close at this
public class WaypointsClass
{
public GameObject[] waypoints;
}
WaypointsClass.waypoints
is an ARRAY! You must use the new
keyword to create array or stuff like that will happen. wp.waypoints = new GameObject[waypoints.Length];
It should look like this
public class MoveEnemy : MonoBehaviour {
public GameObject[] waypoints;
private WaypointsClass wp;
private int currentWaypoint = 0;
void Start () {
WaypointsClass wp = new WaypointsClass();
wp.waypoints = new GameObject[waypoints.Length]; //This line you missed
wp.waypoints = waypoints;
Vector3 startPosition = wp.waypoints[currentWaypoint].transform.position;
EDIT:
From your comment, you can re-use WaypointsClass wp
= new WaypointsClass();
by putting WaypointsClass wp outside the Start
function then initialize it in the Start
function like below:
WaypointsClass wp = null; //Outside (Can be used from other functions)
void Start () {
wp = new WaypointsClass(); //Init
wp.waypoints = new GameObject[waypoints.Length]; //This line you missed
wp.waypoints = waypoints;
Vector3 startPosition = wp.waypoints[currentWaypoint].transform.position;
}