Score/Resource Counter
I'm a beginner game maker and I've made part of a game. I have it so that when a player clicks on a certain item, It disappears. I need to make it so that when the player does this, a number in the top right goes up by 1. If someone could help that would be good. If you need a example of my code I could put it up. Thanks!
Do you want to use a simple sprite or a user interface item like a button?
I want to use a non-interactable number that shows up on screen(a text probably) that goes up by one.@Andrea_$$anonymous$$archetti
Basically I want a UI number that, when the player picks up the item, changes from 0 to 1, 1 to 2, 2 to 3, etc.
Answer by Matthewj866 · May 20, 2017 at 03:29 AM
I am not entirely sure what you mean by "disappears", so I am going to assume that you're either disabling or destroying the object in question.
Assuming you either have an object reference to the scoreboard MonoBehaviour
in the code or have a static reference, you could simply make the value public and alter it in one of two ways depending on if you are disabling it or destroying it.
If you are simply disabling it:
void OnDisable()
{
ScoreBoard.Value++;
ScoreBoard.TextCounter.text = ScoreBoard.Value; //this assigns the number to the text of your UI text box.
}
If you are actually destroying it:
void OnDestroy()
{
ScoreBoard.Value++;
ScoreBoard.TextCounter.text = ScoreBoard.Value;
}
This would need to live on the object that is disappearing.
Hope this helps!
Your answer
Follow this Question
Related Questions
Kill counter doesn't stop counting 0 Answers
My UI Score Is Not Working? 1 Answer
GameOver Score Counter 2 Answers