Now that we have our loss condition, it's time to add in a way for our player to fight back and survive enemy attacks.
Open up EnemyBehavior and modify it with the following code:
public class EnemyBehavior : MonoBehaviour
{
public Transform player;
public Transform patrolRoute;
public List<Transform> locations;
private int locationIndex = 0;
private NavMeshAgent agent;
// 1
private int _lives = 3;
public int EnemyLives
{
// 2
get { return _lives; }
// 3
private set
{
_lives = value;
// 4
if (_lives <= 0)
{
Destroy(this.gameObject);
Debug.Log("Enemy down.");
}
}
}
/* ... No changes to Start,
Update,
InitializePatrolRoute,
MoveToNextPatrolLocation,
OnTriggerEnter...