The error: Object reference not set to an instance of an object, occurs in the commented line of the following code.
public class CarAlone : MonoBehaviour {
public class WaypointsClass {
public Vector3 Waypoint;
public List<Vector3> Neighbors = new List<Vector3> ();
}
public GameObject Waypoints;
public WaypointsClass[] WaypointsArray;
public Transform[] Transforms;
private WaypointsClass StartPoint, Destination;
private CharacterController controller;
bool PlayerStart = false;
void Start () {
controller = GetComponent<CharacterController> ();
GetWaypoints ();
}
void GetWaypoints () {
Transforms = Waypoints.GetComponentsInChildren <Transform> ().ToArray ();
Array.Resize(ref WaypointsArray, Transforms.Length);
for(i = 0; i < Transforms.Length; i++) {
WaypointsArray_.Waypoint = Transforms*.position; //ERROR HAPPENS HERE!!!*_
* }*
* for (i = 0; i < WaypointsArray.Length; i++) {*
* for (j = 0; j < WaypointsArray.Length; j++) {*
_ if(WaypointsArray*.Waypoint != WaypointsArray[j].Waypoint) {
if (WaypointsArray.Waypoint.x == WaypointsArray[j].Waypoint.x || WaypointsArray.Waypoint.z == WaypointsArray[j].Waypoint.z) {
WaypointsArray.Neighbors.Add (WaypointsArray[j].Waypoint);
}
}
}
}
WaypChoice = (int)Mathf.Floor ((float)UnityEngine.Random.Range(0, WaypointsArray.Length - 1));
Destination = WaypointsArray [WaypChoice];
WaypChoice = (int)Mathf.Floor ((float)UnityEngine.Random.Range(0, WaypointsArray.Length - 1));
StartPoint = WaypointsArray [WaypChoice];
}*_
}