How do i make my navmesh agent face the player when it reaches stopping distance?

This is my first time asking question on unity answers. Forgive me if i did something wrong.

My navmesh agent chases player around and starts attacking when close. But when i walk to its back, agent doesnt rotate to my new direction. It keeps playing attack animation to other direction.

Maybe you forgot to include rotations after a unit comes close to you, try adding it like this:

if(DistanceToPlayer <= 3f)
      {
         Vector3 dir = GameObject.Find("Player").transform.position - transform.position;
         Quaternion lookRotation = Quaternion.LookRotation(dir);
         rotation = lookRotation.eulerAngles;
         partToRotate.rotation = Quaternion.Euler(0f, rotation.y, 0f);
         AttackPlayer();
      }