Hello everyone,
I’m working on a prototype simple 2D pathfinder AI that randomly moves about the map. my basic premise is that there is a map template with “nodes” evenly distributed and are destroyed on startup if they are in contact with a wall, then the AI creates a list of all “nodes” within the trigger colliders radius and then removes them from the list when the exit the triggers radius. now the problem comes in when the AI wont add the “nodes” to the list saying that they aren’t gameobjects.
here’s the error : NullReferenceException: Object reference not set to an instance of an object
and here’s the whole script:
using UnityEngine;
using System.Collections.Generic;
public class Enemy_AI : MonoBehaviour {
public float TankSpeed;
public float RotationSpeed;
public GameObject Explosion;
public GameObject Dead;
private List <GameObject> waypoints;
private GameObject CurrentWaypoint;
// Use this for initialization
void Start () {
}
void OnCollisionEnter2D (Collision2D collision2D) {
if (collision2D.transform.tag == "Shell") {
Instantiate (Explosion, transform.position, transform.rotation);
Instantiate(Dead, transform.position, transform.rotation);
Destroy (gameObject);
}
}
void OnTriggerEnter2D(Collider2D entering)
{
if (entering.tag == "Waypoint")
{
waypoints.Add(entering.gameObject);
Debug.Log(waypoints);
}
}
private void OnTriggerExit2D(Collider2D leaving)
{
waypoints.Remove(leaving.gameObject);
}
// Update is called once per frame
void Update () {
transform.Translate(Vector2.up * TankSpeed * Time.deltaTime);
}
}
any help appreciated. two minds are better than one.