Ai attack player when in range.

Ok so basicly i want my zombie ai to attack my player but only when he is in range, this is a 3d game and heres the script and can someone edit it for me and add the part to attack when in a certain radius Thanks im still learning unity.

var myTransform : Transform; //current transform data of this enemy
var isNotDead : boolean = true;
var health : float = 100;
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}

function Start()
{
target = GameObject.FindWithTag(“Player”).transform; //target the player

}

function Update () {

if(health < 1){

	isNotDead = false;
	animation.Play("die");
	Destroy(gameObject, 1);
}

if(isNotDead){

    //rotate to look at the player
    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
    Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);


    
    var distance = Vector3.Distance(target.position, myTransform.position);
    if (distance < 3.0f) {
        animation.Play("attack1");
    }
    else{   
    	//move towards the player
   		myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
   		animation.Play("walk1");
    }

}

}

function ApplyDamage(dmg : float){

health -= dmg;

}

Change the bottom part of your script as follows:

var distance = Vector3.Distance(target.position, myTransform.position);
    if (distance < 3.0f) {
        animation.Play("attack1");
    }
    else if (distance < 15.0f) {   // This is the line that changed
        //move towards the player
        myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
        animation.Play("walk1");
    }