when close/ in range play animation?

what im looking for is for a animation to play when a gameobject ship " is near enemies.

THIS is JavaScript 2d game

var animator : Animator;
var hurt1: AnimationClip;
var range:int;

function Start () {
          animator = GetComponent("Animator");
          animation.clip = hurt1;


if (gameObject.tag == "enemy") >in range (gameObject.tag == "Player")

 animation.Play("hurt1");
}

You can add a trigger to your ship, write a OnTriggerEnter() method, check who’s entered the trigger and play the animation you want.

Check OnTriggerEnter’s doc

Either use Physics.OverlapSphere or OnTriggerStay.But both are expensive in terms of computation. If it’s a mobile game you might need a workaround.