- Home /
GUI text relative to screen?
I a GUI text to be at the top center but all the coding i did for it wont work.
#pragma strict
var offsetY : float =40;
var sizeX : float = 100;
var sizeY : float = 23;
function OnGUI() {
GUI.TextArea(Screen.width/2-sizeX/2, offsetY, sizeX, sizeY)
}
please help quick!
Could you be more specific? "Doesn't work" meaning you don't see anything, or you see something but it's in the wrong spot?
GUI Text is placed relative to the screen on a simple plane. 1,1 is the top right 1,0 middle right, 1,-1 lower right and so on. You might be placing your text outside of that area with numbers over 1.
Answer by Kiwasi · May 21, 2014 at 09:46 AM
GUI.TextArea takes a rect and a string
Change your code to
string TextToEdit;
TextToEdit = GUI.TextArea(new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY),TextToEdit);
No its C#. Sorry, don't speak javascript.
However the methods are the same, you should be able to look each one up in the script reference.
So how would i add this to my code? Can you type this in C# and ill see if it works. You don't have to but i would really appreciate it.
It won't work in javascript as written. However if you follow the link in my answer it will take you to the documentation. In the documentation is an example in javascript.
If you can't make the example from the documentation work then maybe coding isn't for you. Alternatively post the results of using the example in the documentation and I will have another look.