Simple AI Scripting

Hey, i'm making an island game and there is one part of the game, that a Jaguar chases you to kill you. But, i didn't make it yet, i don't know how to make a simple AI script that needs to be like this: if you are in a pre-determinated range, the jaguar starts to chase the player and if the player is reached by the Jaguar it will die, but if the player escapes the Jaguar stops to chase him. Thank's to all.

I'm assuming the jaguar uses a character controller. Use Transform.LookAt to make the jaguar face where the player is, but check the jaguar's distance to the player using Vector3.Distance and check if it is within a certain value. If it is, make the jaguar face him using Transform.LookAt, and make it move in its local forward direction. Use

Vector3 moveDirection = transform.TransformDirection(Vector3.forward);

to get the local forward direction. Use CharacterController.Move to actually move the jaguar.

Also check the value of the earlier Vector3.Distance again. If it is within a smaller value, call Destroy(gameObject, 1.0f) to delete it. The 1.0 means it will wait for 1 second before actually being deleted. Use that time to have it play its death animation perhaps.

static var health : float = 100.0;
var player : Transform;
var speed = 5.0;
var chaseRange = 50.0;
var dieRange = 5.0;
private var controller : CharacterController;

function Start()
{
    controller = GetComponent(CharacterController);
}

function Update()
{
    if (player == null)
        return;

    var range = Vector3.Distance(player.position, transform.position);
    if (range <= dieRange)
    {
        Destroy(player.gameObject);
    }
    else if (range <= chaseRange)
    {
        transform.LookAt(player);
        var moveDirection : Vector3 = transform.TransformDirection(Vector3.forward);
        controller.Move(moveDirection * Time.deltaTime * speed);
    }
}

This helped me a lot!
Thanks ^^