Enemy animation help?

So far my enemy follows me around and deals damage but Im having problems scripting its animations. My script doesn’t seem to be doing anything but basically what I want it to do is play and idle animation until I come close to it and then for it to walk up to me and then attack me, can anyone help me out?

animation.wrapMode = WrapMode.Loop;

animation["idle"].speed = 0.5;

animation["run"].speed = 2;

animation["attack1"].speed = 1;

var target : Transform;

var dist = 15;


function Awake () {

    myTransform = transform; 

}



function Start () {

    target = GameObject.FindWithTag("Player").transform; 

}



function Update () {





  





if(dist < 2){

animation.CrossFade("attack1");

}



if(dist > 2){

animation.CrossFade("run");

}



if(dist > 15){

animation.CrossFade("idle");

}

}

You need to set the distance !

function Update ( )
{
   dist = (transform.position - target.transform.position).sqrMagnitude ;
   dist *= dist ;
}