Hi everyone. I am trying to make a simpe Enemy AI patrol system (which works)
The problem is here, that i want my player to stop WaitForSeconds(3); and afterwards go to the new point and so on, but my coding doesn’t seem to work
All help is appreciated
Here is the code:
using UnityEngine;
using System.Collections;
public class EnemyPatrol : MonoBehaviour {
public Transform[] patrolPoints;
public float moveSpeed;
private int currentPointPosition;
// Use this for initialization
void Start () {
transform.position = patrolPoints[0].position;
currentPointPosition = 0;
}
// Update is called once per frame
void Update () {
if (transform.position == patrolPoints[currentPointPosition].position)
{
currentPointPosition++;
}
if (currentPointPosition >= patrolPoints.Length)
{
currentPointPosition = 0;
}
transform.position = Vector3.MoveTowards(transform.position, patrolPoints[currentPointPosition].position, moveSpeed * Time.deltaTime);
}
}
I was thinking about putting the Couroutine before the CurrenPointPosition++;, but that doesn’t work either