- Home /
TextMesh update causing framerate drop
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();
}
}`
Answer by user-9975 (google) · Mar 07, 2011 at 05:01 AM
Found a solution. I had not used GUIText because last time I used it it was very slow. Apparently last time I had done something wrong. GUIText is working fine now.
Would still be nice to know why 3d Text is so slow.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111548im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
TextMesh 3DText, character size 0 Answers
Accessing the mesh on a TextMesh? 0 Answers
Slow performance on 2D iOS platformer 1 Answer
Show 3d text after collision 2 Answers