Hi there,
I just wanted to ask, if there is a reason, why we’re calculating the distance with Vector.Distance instead of just using the NavMeshAgent.remainingDistance?
I did it like this and it seemed to work just fine:
private void Update()
{
if(target != null)
{
GetComponent().MoveTo(target.position);
if(GetComponent<NavMeshAgent>().remainingDistance < weaponRange)
{
GetComponent<Mover>().StopMove();
}
}
}
Another handy thing with this approach was, that I didn’t get the NullPointerException that happend in the next lesson.
Please let me know if I’m overlooking something. Except the fact that I have to use the UnityEngine.AI namespace … Or is there a downside in using it?
Best regards,
Manuel