Kill counter doesn't stop counting
After i kill the enemy instead of adding one point it adds infinite number of points even after i pause the game it doesn't stop.
Here is my game manager script; using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro;
public class UIManager : MonoBehaviour { public static UIManager instance; [SerializeField] TextMeshProUGUI killCounter_TMP; [HideInInspector] public int killCount ;
private void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
Destroy(gameObject);
}
}
public void UpdateKillCounterUI()
{
killCounter_TMP.text = killCount.ToString();
}
}
and here is my enemy health script; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class EnemyScript : MonoBehaviour { public int EnemyHealth = 10; public GameObject TheZombie; void DeductPoints(int DamageAmount) { EnemyHealth -= DamageAmount;
}
void Update()
{
if (EnemyHealth <= 0)
{
this.GetComponent<ZombieFollow>().enabled = false;
this.TheZombie.GetComponent<Animation>().Play("Dying");
UIManager.instance.killCount++;
UIManager.instance.UpdateKillCounterUI();
EndZombie();
}
}
IEnumerator EndZombie()
{
yield return new WaitForSeconds(3);
Destroy(gameObject);
}
}
Your answer
Follow this Question
Related Questions
Different Score for Active OnMouseDown objects 0 Answers
Scoring only one or zero in one InputField? 0 Answers
GameOver Score Counter 2 Answers
Score/Resource Counter 1 Answer
Add score when camera moves 0 Answers