- Home /
Question by
Cookiemonster04 · Jul 15, 2020 at 01:23 PM ·
bugintcount
Scoring bug error with 2 int variables
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.
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;
public bool triggeron;
void Start()
{
gm = FindObjectOfType<GM>();
score = FindObjectOfType<Score>();
}
void Update()
{
if (triggeron && !gm.gameover)
{
score.Scoree();
triggeron = false;
}
}
void OnTriggerExit2D(Collider2D exit)
{
if (exit.gameObject.tag == "Trigger")
{
score.add++;
triggeron = true;
}
}
Comment
Your answer
Follow this Question
Related Questions
Finding value of an int? 1 Answer
Strange code Debugging 0 Answers
Transform child out of bounds 1 Answer
Instantiate at the wrong position.y 2 Answers
[Error] Error While Importing Packages 0 Answers