Random.Range and Guitext.text

Hi!.

I wanted some random number to appear in my screen every few seconds depending on the set interval but, I’ve discovered that Unity3D can’t maintain the time interval fixed and sometimes get stucked.

Is the setting of the text in Guitext well written?. Maybe I’ve made a bad conversion but I can’t explain the variability of the time when I watch the numbers appear.

Maybe there’s other way to implement this simple question.

Here you are the code.

private var number:int;
function Update () {

if (Time.time>=my_time)
{	
	number =Random.Range(0,9);			
	My_guiText.guiText.text =""+number;
	
	my_time=Time.time+interval;
	
}

}

Okay, I couldn’t find anything wrong so I ran it on my machine and it worked fine. (I hate it when programmers say that, but yeah…) :stuck_out_tongue:

The only thing I can think of is a bit embarassing, but… you’re not confusing it choosing the same random number twice in a row with it not changing, are you? :slight_smile:

The other thing I noticed is that the Inspector value doesn’t change unless I click away from it and back, but the on-screen value changed fine.

You can put a Debug.Log(number) line in there to check that it’s running properly.

The only other possibility I can think of is that you’re maybe adjusting my_time or interval elsewhere in code.