So I have a score counter in my game and I would like the counter to increase incrementally. So, for example, If my player shoots and kills his enemy, I want to add “100” points to my score upon the collision, but I dont want my score to jump from 0 to 100, I want it to count up from 0 until it gets to 100 and then stop.
Does that make sense? Thank you so much for anyone who takes the time to read this.
@PaulSullivan87 If I understand correctly this is what you want. You want to display a score that gets to the target or goal score whenever you get points. Meaning that if you had zero and then pick up something that gives you 5 points then you want to see the UI go, 1,2,3, etc.
Here’s how I would do it:
//You need a variable for the actual score
public int score;
//And you also need a variable that holds the increasing score number, let's call it display score
public int displayScore;
//Variable for the UI Text that will show the score
public Text scoreUI;
//Both scores start at 0
score = 0;
displayScore = 0;
private IEnumerator ScoreUpdater()
if(displayScore < score)
displayScore ++; //Increment the display score by 1
scoreUI.text = displayScore.ToString(); //Write it to the UI
yield return new WaitForSeconds(0.2f); // I used .2 secs but you can update it as fast as you want
So when ever you increment the score variable, the displayScore variable will update to catch up to score by adding 1 every 0.2 seconds.
Hope this helps!
If your score is jumping from 0 to 100, it’s probably due to your script saying so somewhere that whenever the event you want to cause the score increment happens, the value 100 should be added to the score. Where are you changing the value of your score? It should be something like this, assuming you have a variable called “score” to control it’s value (without seeing how you are doing it’s hard to tell exactly):
score += 1;
So I haven’t implemented the scoring script into my game yet b/c every tutorial in Unity (or on youtube) shows how to increase your score by a specific number of points (+100 points for example).