AI enemy scripting help

I need someone to please help me script an enemy AI that will attack my player and return to spawn if hes too far away. I also need this script to be able to play an attack animation an idle animation running and dieing animation. If someone could help me it would be greatly appreciated.

This will get you going:

    var distance;
    var target : Transform;    
    var lookAtDistance = 15.0;
    var attackRange = 10.0;
    var moveSpeed = 5.0;
    var damping = 6.0;
    private var isItAttacking = false;

    function Update () 
    {
    distance = Vector3.Distance(target.position, transform.position);

    if(distance < lookAtDistance)
    {
    isItAttacking = false;
    renderer.material.color = Color.yellow;
    lookAt ();
    }   
    if(distance > lookAtDistance)
    {
    renderer.material.color = Color.green; 
    }
    if(distance < attackRange)
    {
    attack ();
    }
    if(isItAttacking)
    {
    renderer.material.color = Color.red;
    }
}

function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}

function attack ()
{
    isItAttacking = true;
    renderer.material.color = Color.red;

    transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
}

You can always implement other thins like animations and stuff. This simple AI will chase you when you come close enough, until you run away again. Just drag the target you want the AI to follow in the Inspector.

I can give you a little help with the animations. You have to make them your selv, and if you want the AI to do a animation when a certan condition is true.

if(Something happened) // If some event
{
animation.Play("The animations name"); // Then play the animation. 
}

If you still got any questions I can try to explain it more in depth a little later, I have to go to school in a minut ;).