Quantcast
Channel: Questions in topic: "count"
Viewing all articles
Browse latest Browse all 187

Scoring bug error with 2 int variables

$
0
0
Hello, I have a small error occurring when trying to add 2 int variables. I have 1 collider on the player game object & a trigger on each of the gameobject that need to pass thru for scoring. the problem is sometimes it adds 2 when passing only 1 trigger. I need to count how many triggers it passes then add to score. Is there a error in these scripts? Scoring Script: public int score, add, total; public Text text; void Update() { text.text = total.ToString("#,#"); } public void Scoree() { total = score + add; score = total; add = 0; } Player Script: GM gm; Score score; void Start() { gm = FindObjectOfType(); score = FindObjectOfType(); } void Update() { if (triggeron && !gm.gameover) { score.Scoree(); triggeron = false; } } void OnTriggerExit2D(Collider2D exit) { if (exit.gameObject.tag == "Trigger") { score.add++; triggeron = true; } }

Viewing all articles
Browse latest Browse all 187

Trending Articles