You don't have a catch for collision in that code. So it will do that no matter what, even if you collide. Put a Box Collider around the enemy and set it to IsTrigger. Check OnTriggerEnter (other : Collider) to see if that other object is the player. If it is, set your speed to 0 (assuming you want them to stop moving).
Another option is to test their distance from each other and if their distance is less than a number you choose, you stop the NPC.
↧