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

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » Animation help

Animation help

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Animation help on Sun Sep 07, 2014 2:09 am

ni3hthawk


Member [Lv. 0]
Member [Lv. 0]
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
              }
       
          }
    }
}

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum