I am trying to make an enemy movement script for my tower defence game but i keep getting this error and my enemy is not moving
NullReferenceException: Object reference not set to an instance of an object
EnemyMovement.Update () (at Assets/Scripts/EnemyMovement.cs:16)
Here is my script
public float speed = 10f;
private Transform target;
private int wavepointIndex = 0;
void start() {
target = Waypoints.points[0];
}
void Update() {
Vector3 dir = target.position - transform.position;
transform.Translate (dir.normalized * speed * Time.deltaTime, Space.World);
if (Vector3.Distance (transform.position, target.position) <= 0.4f) {
GetNextWaypoint();
}
}
void GetNextWaypoint() {
if (wavepointIndex >= Waypoints.points.Length -1) {
Destroy (gameObject);
return;
}
wavepointIndex++;
target = Waypoints.points [wavepointIndex];
}
If any one knows what the problem is your help is greatly appropriated
thanks
↧