- Home /
Need help for programming the killing of an enemy
How do I make a code in C# that basically says, "if a float (named health) changes from a positive number to a negative number or if the number changes to 0, then.............)"
I didn't want to say "if health <= to 0," because then that makes it so that if you are shooting the dead body, it will kill the enemy again.
Comment
Answer by spilat12 · May 20, 2018 at 08:41 PM
Something like this could help?
int health;
bool isDead;
if(health <= 0 && !isDead)
{
isDead = true;
Die();
}
Or you can even destroy the health script after the enemy is killed, if that is something that might interest you:
if(health <= 0)
{
Die();
Destroy(this); //Removes this script from the gameObject its sitting on
}