I have a simple gun script that applies damage to an enemy. Then i apply a script to the enemy that enables health, fighting animations, and a death animation. The problem is, after i “kill” the enemy it still attacks me and all the animations still play. All i want is so that when i “kill” the enemy no animations play except the death one and the enemy can no longer move or attack. Here is the script:
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var chaseRange = 15.0;
var attackRange = 1.5;
var moveSpeed = 5.0;
var Damping = 6.0;
var attackRepeatTime = 1;
var Tyrant : Transform;
var Health = 100;
var TheDammage = 40;
private var attackTime : float;
var controller : CharacterController;
var gravity : float = 20.0;
private var MoveDirection : Vector3 = Vector3.zero;
function Start ()
{
attackTime = Time.time;
}
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
Dead();
}
}
function Update ()
{
if(RespawnMenuV2.playerIsDead == false)
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance)
{
lookAt();
}
if (Distance < attackRange)
{
attack();
Tyrant.animation.Play("attack01");
}
else if (Distance < chaseRange)
{
Tyrant.animation.Play("run");
chase ();
}
else{
Tyrant.animation.Play("idle");
}
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function chase ()
{
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function attack ()
{
if (Time.time > attackTime)
{
Target.SendMessage("ApplyDammage", TheDammage);
Debug.Log("The Tyrant Has Attacked");
attackTime = Time.time + attackRepeatTime;
}
}
function Dead()
{
Tyrant.animation.Play("death");
}