- Home /
GUI Display
So i am making a Space Game In our Solar System for science. I have a rotater script that makes each planet orbit around the sun. I want to have their speeds Displayed in a GUI Box in the corner. This is the script:
var xSpeed : float = 1;
var ySpeed : float = 1; var zSpeed : float = 1;
var manual : boolean = false;
function Update () {
if( !manual )
{
transform.RotateAround( transform.position, Vector3.right, ySpeed * Time.deltaTime );
transform.RotateAround( transform.position, Vector3.up, xSpeed * Time.deltaTime );
transform.RotateAround( transform.position, Vector3.forward, zSpeed * Time.deltaTime );
}
else
{
if( Input.GetAxis("Horizontal") != 0 )
{
transform.RotateAround( transform.position, Vector3.up, Input.GetAxis("Horizontal")*xSpeed * Time.deltaTime );
}
if( Input.GetAxis("Vertical") != 0 )
{
transform.RotateAround( transform.position, Vector3.right, Input.GetAxis("Vertical")*ySpeed * Time.deltaTime );
}
}
}
Is there a way to show the X speed for each planet? they each have this script with a different x-rotation Value
You just wish to show the xSpeed variable value on the screen?
yes, I only wish to show the x speed, as the others are zero
Answer by barnabasborn.du · Sep 08, 2011 at 06:23 AM
I think if you use the OnGUI function you should be able to get it set up for how you want it.
void OnGUI() { GUI.Box(new Rect(50, 50, 150, 20), "Planet Name's Speed:" + xSpeed); }
the Rect function goes (x position, y position, linewidth, lineheight), add text in " "'s here and to display you rvariables use the + before it like shown. hope this helps.
Answer by sketchers1 · Sep 08, 2011 at 10:15 PM
So, I tried This:
var xSpeed : float = 1;
var ySpeed : float = 1; var zSpeed : float = 1;
var manual : boolean = false;
function Update () {
if( !manual ) {
transform.RotateAround( transform.position, Vector3.right, ySpeed * Time.deltaTime );
transform.RotateAround( transform.position, Vector3.up, xSpeed * Time.deltaTime );
transform.RotateAround( transform.position, Vector3.forward, zSpeed * Time.deltaTime );
} else {
if( Input.GetAxis("Horizontal") != 0 )
{
transform.RotateAround( transform.position, Vector3.up, Input.GetAxis("Horizontal")*xSpeed * Time.deltaTime );
}
if( Input.GetAxis("Vertical") != 0 )
{
transform.RotateAround( transform.position, Vector3.right, Input.GetAxis("Vertical")*ySpeed * Time.deltaTime );
}
}
} function OnGUI () { (GUI.Box(Rect(20, 40, 80, 80), "Jupiter:" + xSpeed)); }
And it worked... Now, For my presentation, I want the number to fluctuate, So even though the x-speed for my planet is 13.07, I want it to have a constant fluctuation between 13.02-13.22 Is there a way to do this? and I would want the fluctuation to be constant..
Your answer
![](https://koobas.hobune.stream/wayback/20220612204559im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Apply a Rotation in World Space based on Quaternions 2 Answers
gimble lock and rotation problem 2 Answers
Scaling a GUI element to fit it's contents 0 Answers
Convert world space to GUI Rect? 5 Answers
Displaying Z Rotation through script 1 Answer