- Home /
Display Object Positions in Gui Box
Hi, so long time since i went near coding. I'm just trying to make a simple GUI box that display the vectors of my object.
function Start()
var xPosition : float;
var yPosition : float;
var zPosition : float;
}
function Update () {
xPosition = transform.position.x;
yPosition = transform.position.y;
zPosition = transform.position.z;
}
function OnGUI(){
GUI.Box(Rect(5,5,240,300)"X : " xPosition " \n Y : " yPosition "\n Z : " zPosition);
}
The \n is for starting on a new line. So anyone got an idea what could be the problem ?
~Wentzel
Answer by whydoidoit · Jun 30, 2012 at 05:22 PM
You have the formatting of that string a bit awry - the fastest way to get you want is just to use this:
function OnGUI(){
GUI.Box(Rect(5,5,200,30), transform.position.ToString());
}
Your existing format string needs a comma before it then:
"X : " + xPosition.ToString() + "\nY : " + yPosition.ToString() + "\nZ: " + zPosition.ToString()
To position it to the left do this:
var myStyle = new GUIStyle("box");
myStyle.alignment = TextAnchor.upperLeft;
GUI.Box(Rect(5,5,200,200), "your string", myStyle);
You can work out the frame rate in update by using this
var xPosition : float; var yPosition : float; var zPosition : float;
function Update () {
xPosition = transform.position.x; yPosition = transform.position.y; zPosition = transform.position.z;
}
var myStyle = new GUIStyle("box"); myStyle.alignment = TextAnchor.upperLeft; myStyle.color = Color.White;
function OnGUI(){ GUI.Box(Rect(5,5,200,200), "X : " + xPosition.ToString() + "\nY : " + yPosition.ToString() + "\nZ : " + zPosition.ToString() + "\nFPS : " + FramesPerSecond.framesPerSecond , myStyle);
GUI.Box(Rect(0,0,200,200), "" );
}
So i'm just trying to add a white color to the GUI, when it's under the OnGUI function the Gui box just dissappears ?
Appreciate the help.
Answer by Wentzel · Jun 30, 2012 at 05:56 PM
Appreciate the help @ Mike (whydoidoit) Just two more questions,
How can display the frames per seconds also ?
Is there some way i can move the text to the left of the Box ?
Your answer
Follow this Question
Related Questions
Help with using keys to activate scripts 2 Answers
TouchPad in C# 3 Answers
How to add textboxes in Unity 3d 3 Answers
Can't display PNG texture within GUI calls 1 Answer
Switching Between Weapons? 1 Answer