Hi,
So I have an object called goblin, when its health is empty, I want it to play an death animation and then to be destroyed.
But when I put that in the script, it plays the animation in loop, even when I tell it to play it once…
If somebody coul help me because I’m really stuck…
Here is the script :
using UnityEngine;
using System.Collections;
public class attackGoblin : MonoBehaviour {
Animation anim;
public int currentHealth;
public int dead = 1;
bool isDead;
bool damaged;
public void stop()
{
currentHealth = currentHealth - 20;
}
public void walk()
{
anim["attack1"].wrapMode = WrapMode.Once;
anim.Play("attack1");
}
void Start(){
anim = GetComponent<Animation> ();
currentHealth = 100;
}
void Update(){
var goblin = GameObject.Find("GOBLIN");
var creature = GameObject.Find("creature1");
var distance = Vector3.Distance(goblin.transform.position, creature.transform.position);
//Debug.Log(distance);
if (currentHealth > 0)
{
if (!anim.IsPlaying("attack1"))
{
Debug.Log(currentHealth);
if (distance < 2)
{
anim.Play("combat_idle");
}
if (distance >= 2)
{
anim.Play("idle");
}
}
}
else if(currentHealth<=0)
{
anim["death"].wrapMode = WrapMode.Once;
anim.Play("death");
if (!anim.IsPlaying("death"))
{
Destroy(goblin);
}
}
}
}