Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Share
Go down
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 1444
Rep : 0
Join date : 2014-09-06
View user profile

Animation help

on Sun Sep 07, 2014 2:09 am
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
              }
       
          }
    }
}
Back to top
Permissions in this forum:
You cannot reply to topics in this forum