I am relatively new to unity and C#. I am trying to make a simple dungeon crawling game. Everything is working fine, apart from the code for my enemies health. the if statement telling the game to destroy the enemy game object makes them die as soon as the game is played. An identical piece of code is used for the player and this works fine. any help would be greatly appreciated. code is below, the part that isn’t working is the comment at the end.
Thanks in advance!
public class StrEnemyHealth : MonoBehaviour {
int StrEnHealth = 20;
void OnTriggerEnter(Collider collision)
{
//takes health from enemy
if (collision.gameObject.tag == "Player")
{
StrEnHealth-=PlayerStats.Att;
Debug.Log("enemy health:" +StrEnHealth);
}
}
/*
//kills enemy if health is 0
void Update()
{
if (StrEnHealth <= 0);
{
Debug.Log("enemy dead!");
Destroy(gameObject);
}
}
*/
}