Hi all. When you kill an enemy, score must increase 1 point. It works at first enemy but when you kill other enemies it just stays at 1. Enemies spawn periodically. How can I solve it?`
public class Zombie : MonoBehaviour
{
int score = 0;
private bool isDead = false;
public Text ScoreText;
public void TakeDamage(int amount)
{
health -= amount;
if (health <= 0)
isDead = true;
Die();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.transform.tag == "Bullet")
{
TakeDamage(30);
}
}
private void Die()
{
if (isDead)
{
score++;
ScoreText.text = "" + score;
Debug.Log("SKOR: " + score);
isDead = false;
Destroy(gameObject);
}
}
}
`