x


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();

}

}`

more ▼

asked Mar 06 '11 at 06:29 AM

user-9975 (google) gravatar image

user-9975 (google)
11 1 1 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 07 '11 at 05:01 AM

user-9975 (google) gravatar image

user-9975 (google)
11 1 1 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2028
x280
x185
x105
x105

asked: Mar 06 '11 at 06:29 AM

Seen: 982 times

Last Updated: Mar 06 '11 at 06:29 AM