hello, im new to unity3d and im having trouble with the "die" animation. i can't seem to get it work. Here is my script:
public int health = 100;
public TextMesh tm;
public AnimationClip dead;
void Start () {
tm = GetComponentInChildren ();
}
// Update is called once per frame
void Update () {
tm.text = "Health : " + health.ToString();
if (health<0)
{
health = 0;
GetComponent().Play(dead.name);
}
}
public void GetHit(int damage)
{
if(health <= 0)
{
Destroy(this.gameObject);
}
health -= damage;
}
}
Anyone know how to fix it?
↧