It feels like it’d be nicer not to have two if statements in EngageTarget.
Instead of
if (distanceToTarget >= navMeshAgent.stoppingDistance)
{
ChaseTarget();
}
if (distanceToTarget <= navMeshAgent.stoppingDistance)
{
AttackTarget();
}
Write:
if (distanceToTarget >= navMeshAgent.stoppingDistance)
{
ChaseTarget();
}
else
{
AttackTarget();
}
Note that the two examples are not exactly equivalent because the original code has an overlap when distanceToTarget == navMeshAgent.stoppingDistance but I’m not sure if it’s useful.