NullReferenceException: Object reference not set to an instance of an object
patrol.Start () (at Assets/scripts/patrol.cs:13) and NullReferenceException: Object reference not set to an instance of an object
patrol.Update () (at Assets/scripts/patrol.cs:20). I don’t know what to do so please help. Here is my script.
using UnityEngine;
using System.Collections;
public class patrol : 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++;
}
if (currentPoint >= patrolpoints.Length)
{
currentPoint = 0;
}
transform.position = Vector3.MoveTowards (transform.position, patrolpoints [currentPoint].position, moveSpeed * Time.deltaTime);
}
}