Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

IndexOutOfRangeExeption: Array index is out of range

$
0
0
I Tried to make a waypoint system with the following code. I get the error above, but the strange this is that everything works fine... What could it be? (Error at line 28). using UnityEngine; using System.Collections; public class EnemyWitchEngine : MonoBehaviour { public Transform[] waypoints; public float normalSpeed = 2; public float attackSpeed = 3; public int currentWaypoint = 0; //private Transform target; void Start () { //target = GameObject.Find ("First Person Controller").transform; } void Update () { //Vector3 correctTarget = new Vector3(target.position.x, transform.position.y, target.position.z); //transform.LookAt(correctTarget); if (waypoints.Length == 0) { print("You need to assign some waypoints within the Inspector"); } if(currentWaypoint >= waypoints.Length || currentWaypoint < 0) { currentWaypoint = 0; } if(Vector3.Distance(waypoints[currentWaypoint].position, transform.position) <= 0.1f) { //next waypoint currentWaypoint ++; } else { transform.position = Vector3.MoveTowards(transform.position, waypoints[currentWaypoint].position, normalSpeed * Time.deltaTime); transform.LookAt(waypoints[currentWaypoint]); } } } ![alt text][1] [1]: /storage/temp/23826-problem.jpg

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>