This is attached to the Enemy object and it requires a parent GameObject with patrol points, as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyBehavior : MonoBehaviour
{
public Transform player;
public Transform patrolRoute;
public List<Transform> locations;
private int locationIndex = 0;
private NavMeshAgent agent;
private int _lives = 3;
public int Lives
{
get { return _lives; }
private set
{
_lives = value;
if (_lives <= 0)
{
Destroy(this.gameObject);
Debug.Log("Enemy down.");
}
}
}
void Start()
{
agent = GetComponent<NavMeshAgent>();
player = GameObject.Find("Player").transform;
InitializePatrolRoute();
MoveToNextPatrolLocation();
}
void Update()
{
if (agent.remainingDistance...