How to implement animation in the AI script.

Hi all,
i am learning about the process of making games and i’m currently complete noob. I make a zombie game based on Angry Bots character, i have a zombie model from PixelHouse, i’ve found an AI script for this zombie here .

var player : GameObject; var speed : float = 1;

function Start () { player = GameObject.FindGameObjectWithTag("Player");

if (!player)
Debug.Log ("ERROR could not find Player!");

}
function Update() { if (!player) return;

var distance = Vector3.Distance( player.transform.position, transform.position);

if ( distance < 60 )
{
Debug.Log ("player is close");

var delta = player.transform.position - transform.position;
delta.Normalize();

var moveSpeed = speed * Time.deltaTime;

transform.position = transform.position + (delta * moveSpeed);
}
else 
{
Debug.Log("not close yet " + distance);
}
}

That’s the code. Also thank you, goatria!

However i have a small problem. I don’t know how (and where exactly) to insert an animation events in this script. I know that this is kinda simple, but as i mentioned it above, i am completly newb in scripting.
Here is a preferences of zombie.

Heres the video of da game. As you see, following player works, i want to make animation work too.
Any help appreciated.

if the distance is less than 60 then play the animation you want maybe attack like this animation.Play(“Name of your animation”);

Thank you. Another stupid question - how would i make’em rotate? He only faces one place.
I know, this is something like “transform.rotate”.

If you want him to look at the player you could do
var target : Transform;
function Update()
{
transform.LookAt(target);
}

If you are able to jump some wired things may happen add this underneath incase the zombie looks everywhere

transform.eularAngles.x = 0;

This will restrict the zombies looking position to make sure he and his body do not look in the air