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]);
}
}
}