I am trying to get a capsule to fall over when the player deals enough damage to it. But when the capsules health reaches 0 the animation will not play. I have googled this and nothing seems to fix the problem. Please Help!! :,(
-capsule Take Damage code
#pragma strict
var health : float;
var CapsuleClip : AnimationClip;
function Update() //checks if capsule's health is at zero
{
if (health <= 0)
{
GameObject.Find("Capsule").animation.Play("dead"); //plays death animation
}
}
function ApplyDamage(TheDamage : int) //decreases capsule's health
{
health -= TheDamage;
}
-player Send Damage code
#pragma strict
var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float;
function Update()
{
if (Input.GetKeyDown("e")) //attacks
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit)) //gets distance to capsule
{
Distance = hit.distance;
if (hit.distance <= MaxDistance) //checks if attacker is in range
{
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
//sends message to capsule
}
}
}
}
-capsule Take Damage code
#pragma strict
var health : float;
var CapsuleClip : AnimationClip;
function Update() //checks if capsule's health is at zero
{
if (health <= 0)
{
GameObject.Find("Capsule").animation.Play("dead"); //plays death animation
}
}
function ApplyDamage(TheDamage : int) //decreases capsule's health
{
health -= TheDamage;
}
-player Send Damage code
#pragma strict
var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float;
function Update()
{
if (Input.GetKeyDown("e")) //attacks
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit)) //gets distance to capsule
{
Distance = hit.distance;
if (hit.distance <= MaxDistance) //checks if attacker is in range
{
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
//sends message to capsule
}
}
}
}