public class EnemyHealth : MonoBehaviour
{
public float EnemyH = 20f;
public float damageAmount = 10f;
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "Bullet")
{
EnemyH -= damageAmount;
}
}
private void Update()
{
EnemyDeath();
}
void EnemyDeath()
{
if(EnemyH < 1)
{
Destroy(gameObject);
}
}
}
I want to make a enemy health scipt that will destroy the enemy if the health reaches 0, does anybody know why it doesnt work ?, public class EnemyHealth : MonoBehaviour
{
public float EnemyH = 20f;
public float damageAmount = 10f;
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "Bullet")
{
EnemyH -= damageAmount;
}
}
private void Update()
{
EnemyDeath();
}
void EnemyDeath()
{
if(EnemyH < 1)
{
Destroy(gameObject);
}
}
}
I want to make a enemy health scipt that will destroy the enemy if the health reaches 0, does anybody know why it doesnt work ?