Animate a count | how to make a count to grow smoothly ?
I'm new at unity
I'm making a game, there is a score. Each time when the player gets points, I want that score to grow slowly, not instantly. ( The score is shown in a n UI.Text )
Any ideas ?
Answer by Glurth · Feb 29, 2016 at 04:56 PM
Keep TWO scores: currentMAXscore, and currentScore. Slowly increment, based on a timer value, the currentScore (and display that), untill it reaches the currentMaxScore. You will also need a variable that determine HOW FAST to increment the score, lets call it scoreIncreaseRate (defines how much the score should increase every second).
Inside Update() you could do the following (example only, never compiled)
if(currentScore<currentMAXscore)
{
int ScoreIncrement=Time.deltaTime * scoreIncreaseRate;
currentScore+=ScoreIncrement
if(currentScore>currentMAXscore)
currentScore=currentMAXscore;
}
Time.deltaTime doesn't work with integers unless you convert it to one i.e
int ScoreIncrement = (Int32)Time.deltaTime * 1;
that said, you can use floats just fine in this use case ins$$anonymous$$d of integers, but I do want to note that it'd might be best to use unscaledDeltaTime ins$$anonymous$$d of deltaTime, because the former is not affected by Time.Timescale (unless you want to be able to slow down the score counter as well when slowing down the rest of the game)
Your answer
Follow this Question
Related Questions
How Can I put a Dialogue of each Questions in the inspector? 0 Answers
Animate Text letter by letter 3 Answers
Simple Game Over script 2 Answers
How can I delete a line of UI Text? 0 Answers
GUI Text not showing up :( 7 Answers