I was following a guide to make a simple game and followed everything almost perfectly but for some reason i get 3 seperate NullReferanceException’s
NullReferenceException: Object reference not set to an instance of an object
enemyPatrol.Start () (at Assets/scripts/enemyPatrol.cs:12)
NullReferenceException: Object reference not set to an instance of an object
enemyPatrol.Update () (at Assets/scripts/enemyPatrol.cs:21)
and
NullReferenceException: Object reference not set to an instance of an object
enemyPatrol.Update () (at Assets/scripts/enemyPatrol.cs:21)
UnityEditor.Toolbar:OnGUI()
Here’s the script it’s coming from
using UnityEngine;
using System.Collections;
public class enemyPatrol : MonoBehaviour {
public Transform [] patrolPoints;
public float moveSpeed;
private int currentPoint;
// Use this for initialization
void Start ()
{
transform.position = patrolPoints [0].position;
currentPoint = 0;
}
// Update is called once per frame
void Update () {
if (transform.position == patrolPoints [currentPoint].position)
{
currentPoint++;//++ adds 1 to amount
}
if (currentPoint >= patrolPoints.Length)
{
currentPoint = 0;
}
transform.position = Vector3.MoveTowards (transform.position, patrolPoints [currentPoint].position, moveSpeed * Time.deltaTime);
}
}
It’s attached to an enemy cube wich just has to move around but when i press play it just keeps pausing it and showing the errors mentioned above. If there is any more info i should give to help please tell me. Thanks!