- Home /
ScoreBoard Help
Heya, new to Unity. Was following a tutorial on scoring system that increase the score when a collectible is collected. Was wondering how do you reduce the score? (Example the UI is showing how many crystal is remaining and with each crystal collected, the amount is reduce) Been trying but i cant seem to get it.
public class GemPoint : MonoBehaviour { public GameObject scoreBox; public AudioSource collectSound;
void OnTriggerEnter()
{
GlobalScore.currentScore -= 1;
collectSound.Play();
Destroy(gameObject);
}
public class GlobalScore : MonoBehaviour { public GameObject scoreBox; public static int currentScore; public int InternalScore;
// Update is called once per frame
void Update()
{
InternalScore = currentScore;
scoreBox.GetComponent<Text>().text = "" + InternalScore;
}
Answer by qsp18 · Dec 07, 2020 at 02:57 PM
You make a second Text in ur UI for example "remainingCristals"
add to ur update function, if u have 10 cristals:
remainingCristals.GetComponent().text = (10 - InternalScore).ToString();
Heya, so uh apparently i didnt have to add anything new. I tried and error and found that you just have to add ToString and the number in the score for it to works.
Thank you very much
public class GlobalScore : $$anonymous$$onoBehaviour { public GameObject scoreBox; public static int currentScore; public int InternalScore;
// Update is called once per frame
void Update()
{
InternalScore = currentScore;
scoreBox.GetComponent<Text>().text = (10 + InternalScore).ToString();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613021220im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to fix this Score UI problem 2 Answers
Multiple score values 1 Answer
Adding value from a clone object to score 4 Answers
Scoring Points. 1 Answer
Multiple objects being destroyed, count for them being destroyed doesnt go up past once. 2 Answers