I have a TextMesh that is intended to display the player's score. Instead of just changing the score, I wanted it to count up like an odometer when the player earns points. When I use this script, the score is counted the way I want it to be, but the game skips while updating the display.text string. It works smoothly on my Mac, but has these issues on my second gen iPod Touch.
Is there anything fundamentally wrong with my code? Is there a more efficient way to do this? Is there anything else I should be doing?
//Management holds the static score variable
@HideInInspector var display : TextMesh;
@HideInInspector var displayScore : int = 0;
var timer : float = 0;
var dif : int = 0;
function Start () {
display = gameObject.GetComponent(TextMesh);
}
function Update () {
timer = timer + Time.deltaTime;
//Update the score eight times each second
if (timer > .125) {
dif = Management.score - displayScore;
//Each 1/8sec, add a third of the score difference so it 'counts up'
displayScore = displayScore + (dif / 3) + (dif % 3);
timer = timer - .125;
display.text = "SCORE: " + displayScore.ToString();
}
}`