How to make 1 enemy randomly walk in NavMeshAgent and if in certain range of player, speed up gradually and follow the player?

Please help!
I am trying to make a horror game where the enemy is wandering slowly and I have to collect objects, if the enemy is in range of the player I want the enemy to speed up and quickly start following the player, until unless the player runs away, where the enemy will go back to wandering, please help!
I am new, so please leave comments in the scripts so I can understand, thanks!


There are a lot of threads and tutorials about it. I suggest you to look up on google and youtube :wink:

I quickly found that, but there is a lot more

Sorry but it didn’t help, the video uses networking which won’t help me as this game is a 1 player game