There are many ways in which you could detect if a player is close. I guess a spherecollider and relying on OnTriggerEnter is a good way to go, just remember to check it the collider is tag "Player". As for the fleeing then that part is hard to answer as we don't know anything about your game. Is it a top-down 2d game? First person shooter? Isometric turn-based RPG? Whatever the case it should be easy enough to get something to move in the opposite direction of the player.