I’m trying to get the character deleted when HP reaches zero but nothing happens, what’s going on?
the code:
var GameOver: AudioClip;
function update ()
{
if(HealthVar.Health <= 0)
Destroy (gameObject);
AudioSource.PlayClipAtPoint(GameOver, transform.position);
}
Create a c# class and put this on any gameObject. Hit play and you will see how is deleted when health reaches 0
public class MyClass : MonoBehaviour{
public int health;
public Start()
{
health = 100;
}
public Update(){
health -= 0.5f;
if(health <= 0){
Destroy(gameObject);
}
}
}