- Home /
Randomize GUI Position
is it possible to use a random.range inside a gui? for exemple:
GUI.Label(Rect(Screen.width/2+80, Sceen.height/2 (Random.Range(-125,80)) , 100,100, "");
hope someone can help, thanks.
Answer by ina · Jan 20, 2012 at 04:01 PM
The OnGUI is updated every frame, so this will be very "jumpy"... You probably want to use Lerp to smooth it out...
You are missing a * for multiply for it to work. Also, Rect has 4 parameters:
GUI.Label(Rect(Screen.width/2+80, Screen.height/2 * Random.Range(-125,80),100,100) , "jumpy");
Good point, @ina - used this way, Random.Range will produce very shaky elements - it should be called at decent intervals, or smoothed out with Lerp like you suggested.
Answer by aldonaletto · Jan 20, 2012 at 04:01 PM
No trouble - you can use any Random or Mathf function as argument. Random.Range comes in two flavors: if you pass integer arguments (like in your example), it returns an integer >= min and < max, thus in your example the range is actually -125 to 79. If you pass float arguments (-125.0 to 80.0, for instance), a float >= -125 and
Your answer
![](https://koobas.hobune.stream/wayback/20220613063219im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUILabel doesn't show up 1 Answer
Score display not working 1 Answer
GUI Label on GameObject Problem 1 Answer
Player label appears in sky! 0 Answers
How to change how meany decimals are in a GUI sound slider 2 Answers