Player following a NPC

In my game I want you to follow a NPC that has a set path. This NPC waits for you if your too far away and it needs to play a walking animation and when waiting an idle animation. The only problem is that i havent found anything on the internet explaining how you can achieve this, so if anyone can help, please answer

To stop when the player is too far away: Unity - Scripting API: AI.NavMeshAgent.isStopped

Animation: You would use the agent’s speed to control the animation Unity - Scripting API: AI.NavMeshAgent.velocity

In Mecanim what I do is I pass in the speed as animation parameters. If the speed is zero, play standing animation. If speed is max → walking animation. The velocity has components, which is useful for different walking animations. If your NPC is walking sideways (maybe they are firing at monsters while moving to the destination) you can make them walk sideways or backwards. Mecanim makes all this pretty easy and there are many tutorials.