How to Update GuiText.Text?

Hi,

I’m trying to do something really simple but failing miserably :frowning:

Basically, I’m simply trying to put a variable in a GuiText.Text and then have it update on screen. But, the variable I plug in the GuiText doesn’t update. I know it’s working as it works in the debug.log (counts to 99). I’ve spent about an hour looking for solutions but with no success, hopefully someone can solve my problem?

static var framecount : int;

function Update () {

for (var framecount=0; framecount<=99; framecount++){

Debug.Log("framecount is "+framecount);

guiText.text = "Framecount is : "+framecount;

}

}

The result of this is the GUIText displaying ‘99’ and not updating. Almost as if I’d assigned the variable directly to GuiText.Text. Weird.

I’m guessing that updating the GuiText.text is going to take a bit more work? But I can’t understand why this works:

http://www.unity3dstudent.com/2010/07/beginner-b14-gui-text-and-counters/

As this also plugs a variable into the GuiText.Text and works fine.

Flumoxed :frowning:

Thanks for any help.

2 Answers

2

Everything in an Update happens in one frame. So it’s doing the loop, then updating.
If you want to see it count up, you should increment the variable only in Update (not a loop ,just increment it if it’s less than 99).

Thanks for that. It works now.