x


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;

}

}

more ▼

asked Mar 02 '12 at 12:53 PM

jorgon gravatar image

jorgon
77 26 34 35

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

1 answer: sort voted first

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..) :P

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? :)

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.

more ▼

answered Mar 02 '12 at 05:31 PM

JinxM gravatar image

JinxM
226 1 3

HEY!!...That's the right answer!!: it's possible that due to the nature of the Random function randomly I generate two times in a row the same number and it gives the sensation of a more persistent number in the timeline. THANK YOU VERY MUCH!. Problem solved.

Mar 23 '12 at 09:35 AM jorgon
(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:

x571
x313
x106

asked: Mar 02 '12 at 12:53 PM

Seen: 481 times

Last Updated: Mar 23 '12 at 09:35 AM