I’m new to Unity so sorry in advance if this is a basic question, I attached a variable that should add by 1 every time OnTriggerEnter2D is triggered. It however is not adding by 1 but adding constantly. Can please tell me what I’m doing wrong?
Here is where I’m calling it
public class MonsterTarget : MonoBehaviour {
public Resetter Resetting;
public ScoreCount ScoreHit;
public float targetHit = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnTriggerEnter2D(Collider2D col)
{
targetHit ++;
Resetting.Reset();
}
}
and this is where its going
public MonsterTarget monTarget;
public Text scoreText;
public Text highScoreText;
public float scoreCount;
public float highScoreCount;
public bool scoreIncreasing;
// Use this for initialization
void Start () {
if(PlayerPrefs.HasKey("HighScore"))
{
highScoreCount = PlayerPrefs.GetFloat("HighScore");
}
}
// Update is called once per frame
void Update () {
if (scoreIncreasing)
{
scoreCount += monTarget.targetHit;//RIGH HERE IS WHERE IM CALLING IT
}
if (scoreCount > highScoreCount)
{
highScoreCount = scoreCount;
PlayerPrefs.SetFloat("HighScore", highScoreCount);
}
scoreText.text = "Score: " + Mathf.Round(scoreCount);
highScoreText.text = "High Score: " + Mathf.Round(highScoreCount);
}
}