Hey, I want to recreate a score increasing effect in Unity where it starts really fast, but goes slower towards the end.
Many video games use this, but I couldn’t find an example video so I only have this video of a punch machine:
This score is exactly what I’m trying to replicate in Unity, but I’m stuck finding a good way that works with both low and high scores.
My idea was to use Mathf.Pow
, but this didn’t really work.
Currently I have this which increases my score inside of a coroutine:
int _score = PlayerPrefs.GetInt("Score");
int _currentScore = 0;
while(_currentScore < _score)
{
_currentScore++;
_scoreText.text = _currentScore.ToString();
yield return new WaitForSeconds(.001f);
}
This method works fine, but takes really long for high scores and isn’t really exciting to watch.
Maybe you have an idea how I can recreate this score effect, which starts really fast and goes slower towards the end.
I like to have two quantities for this:
int actualScore;
int displayedScore = 1;
When the game logic adds points, it does this:
actualScore += 12345;
Now over in the display logic you periodically:
Now… onto the magic.
Obviously if you count one point (or any constant amount) it is pretty uninteresting… a huge score add might take forever to get together.
Keeping it all as integers, here is the approach I like to use for computing how much to .MoveTowards() each iteration:

have a basic nonzero constant amount (for instance, 1)

have a fraction of the difference (say 1/5th, or one fifth)
Add the two above terms together and use that as the amount to move.
void Update()
{
int difference = actualScore  displayedScore;
if (difference != 0)
{
int constantTerm = 1;
int proportionalTerm = difference / 5;
int moveStep = Mathf.Abs( proportionalTerm) + constantTerm;
displayedScore = (int)Mathf.MoveTowards( displayedScore, actualScore, moveStep);
/// now use displayedScore to update your text output
}
}
NOTE: the above is highly frameratedependent. One way to address that is to put the above in a loop in a coroutine:
// run this once and once only, and it runs forever during score display.
// it can even live right on your score display UI scripts
IEnumerator MyAlwaysRunningScoreUpdater()
{
while(true)
{
yield return new WaitForSeconds( 0.1f);
//  insert the guts of the Update() function code above right here
}
}
1 Like