- Home /
Question by
Kreativity · Jul 23, 2014 at 11:13 PM ·
error
Out of Range Exception
So I'm doing a patrol walk from point to point enemy but when it walks to the first point it stops and I get a script array out of range error and he won't move and a line of text goes yellow.
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++;
}
transform.position = Vector3.MoveTowards(transform.localPosition, patrolPoints[currentPoint].position, moveSpeed * Time.deltaTime);
}
}
Comment
Answer by cdrandin · Jul 23, 2014 at 11:24 PM
Hiya, first of all in start you have ...
transform.position = patrolPoints[0].position;
If in the inspector, patrolPointsis size 0, then patrolPoints[0] doesn't exist, thus being out of range exception.
Double check your container in the inspector.
If that is not the case then it is your counter, extending beyon the bounds of your list.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error CS1519 Help 1 Answer
Built game error 0 Answers
Need help syntax error 1 Answer
I am having problems uploading my project to Xcode Can anyone help??? 0 Answers