- Home /
GUI Formatting Problem
Hi, In OnGUI, how do I create a box that displays the lives a user has left? For example 5x [Image of a heart here] I tried GUI.Box(new Rect (235, 10, 115, 30), GUIContent(lifePic, "hello"), myGUIStyle); but this places the image on the left of the text when i want it on the right. Is there no way to change this? Thanks in advance for your time.
Answer by Codetastic · Sep 14, 2012 at 06:55 AM
You will probably have to place each element separately:
GUI.Box(new Rect (235, 10, 115, 30), "",myGUIStyle);
GUI.Label(new Rect (275, 14, 115, 30), "5x",myGUIStyle);
GUI.Label(new Rect (292, 10, 115, 30), lifePic);
Thanks for the answer, but i'm worried there will be a formatting difference between when its say 5 X [LIFE} and 1000000000000 X [LIFE]. Not that its likely to get to such a case....but it'd be nice to have a way that could deal with all situations. There must be a nicer way to place an image on the right of text in a box without resorting to hackery!?
Whoops forgot to mention (and add it to example code for that matter, edited now), that you can set your "myGUIStyle"'s "Alignment" to upper right (or any right) so that the text always ends where you want and "grows" to the left ins$$anonymous$$d of right.
Your answer

Follow this Question
Related Questions
How to position 3D-GUI-Mesh on change of aspect ratio? 0 Answers
Scrolling Text 1 Answer
How To Make A Floating Health Bar 1 Answer
Button Turns Off and On Object 1 Answer
Wearied Error 1 Answer