|
I can't seem to figure out how to use the Screen.width and Screen.height correctly. I have the resolution at 4:3, and no matter what, when I build what I am working on, the text shows up in the middle of the field as opposed to the right side of the screen as I intended. Can anyone help me out with how to script the Screen.width and Screen.height with text I want to display on the screen, like through GUI.label? function OnGUI(){
}
(comments are locked)
|
|
Are you talking about the placement of the label on the screen, or the placement/alignment of text within that label? For the latter, you need to adapt the settings of the associated GUIStyle (check the docs for that, I never used it so far). For the former it is simple once you understand what Rect(x,y,w,h) does. Rect() always refers to the upper left corner of an object, and the coordinates are always relative to the upper left screen corner. So to place the upper left corner of an object at screen coordinates (200,100), use
(with appropriately defined valued for widthOfObject and heightOfObject). Now if you want to place that same object relative to the upper RIGHT screen corner, for example, you can compute the correct pixel position of the upper left corner of your object with with:
This is analogue for the y coordinate. I do want the Label to be relative to the right edge of the screen. I utilized the second example you posted, and it works when I run the program through the Unity3D interface, but when I build and run it, the text remains at the center of the screen. Any ideas?
Oct 21 '10 at 05:59 PM
Wylie
Nevermind! I got it to work, it wasn't a problem with the scripting, it was a bug in the editor. I just updated the project to unity 3.0 and it built great. Thanks for the help!
Oct 21 '10 at 08:52 PM
Wylie
Thanks for sharing this answer! This just helped me a bunch as well! Good stuff!
Aug 08 '12 at 08:50 PM
Tethys
(comments are locked)
|
|
If you want the text right justified in the rect you're going to need to pass in a style to the GUI.Label. See: http://unity3d.com/support/documentation/ScriptReference/GUIStyle.html
(comments are locked)
|

Could you post your script or a portion of the script that you are using?
Hey, ClandestineMan! I edited the question with the script in question.