- Home /
Scoring zones work, but need score to be cumulative.
Hello! I have six different zones for scoring, three which award 1 point, two which award 3 points, and the ground level which subtracts 1 point. These all work as intended on their own (egg goes into 1 point basket, 1 point appears where I need it to), but when I drop an egg into another zone, it displays it's own score in the same area as the others.
My question is how do I make the individual scores add/subtract to/from a "total" score instead of the score for each individual zone?
public Text scoreText;
private int score;
public int pointValue;
private void Start()
{
score = 0;
}
private void Update()
{
}
public void OnTriggerEnter(Collider other)
{
UpdateScore(pointValue + score);
}
public void UpdateScore(int scoreToAdd)
{
score = +scoreToAdd;
scoreText.text = "Score : " + score;
}
Thank you in advance!!
Answer by TwitchyOrphan · Nov 17, 2021 at 02:05 PM
Found an answer on another thread this morning. For anyone else needing to add several numbers from separate triggers, use the word "static". This did exactly what I needed.
I changed private int score; to private static int score; and it worked like a charm.