- Home /
Odd question... can a GUIText object be displayed upside-down?
Hi guys and girls,
I was wondering if it's possible to somehow rotate a GUIText object 180 degrees on the z axis? I have tried in the inspector, but nothing works... can text be displayed in any other orientation other than the default?
I have a part of my game that makes use of an upside-down camera and I need the HUD to match and would rather not have to do everything with png files...
Cheers!
Could try copy pasting from here to there: http://www.fliptext.org/ Dunno if that'd work, be funny if it did though.
Also interesting whether GUIText could be rotated by +- 90 deg. I have managed fo find the solution for rotating the texture with GUIUtility.RotateAroundPivot, possibly that would work with the text as well
LOL, I wish. I'm using custom fonts and also a lot of it is dynamic text, scores etc... so I can't just copy paste... if it were that simple, I'd use image files. Thanks, though!
Sorry, tomekkie2, that reply was for the comment above... Just saw yours now. Will try.
I have recalled and tested that again, have a look at my answer at the bottom.
Answer by CHPedersen · Jun 21, 2012 at 01:29 PM
You can accomplish that by modifying GUI.matrix. Higgy B has explained how on the forum if you follow this link:
http://forum.unity3d.com/threads/6954-video-intro?p=53105#post53105
Simply put, the GUI.matrix is an overall Translation, Rotation and Scale (TRS) which is applied globally to all GUI elements when they're being drawn. If you change it, it affects all subsequent GUI elements.
You can use it to set your rotation to 180 on the Z axis, draw your label (upside down), then set it back to its original value, then draw the rest of your GUI. It will accomplish what you're asking.
Update with code sample:
Here's how to draw only one thing with a changed GUI.matrix:
Matrix4x4 guiMatrixOrig = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, 180), new Vector3(1.0f, 1.0f, 1.0f)); // No translation, 180 rotation on Z, no scaling.
// Draw something upside down now:
GUILayout.Label("Whatever text is upside down here");
// Reset the matrix to its original value
GUI.matrix = guiMatrixOrig;
GUILayout.Label("This text is normal since the matrix just got reset...");
Edit: Sorry, I misread your post and didn't realize you were asking about a GUIText object. I'm not sure those are drawn using GUI.matrix, since they're GameObjects. In any case, the above will do what you want if you convert to using a GUI.Label ins$$anonymous$$d of a GUIText object. ;)
Ah... But it affects all GUI objects? I can't just have one upside-down and the rest default?
Oh, wait... I could use labels for some (upside down) and guitext for others. Thanks!
No, don't do that. :) You don't need GUIText objects for some things and GUI.Labels for others. Like a lot of other things in Unity, modifying the GUI.matrix works like a state machine. Everything drawn BEFORE you change it is normal, everything drawn AFTER you change it gets affected. When you don't want things to get drawn upside down anymore, you just change it back. Read my answer again. That is what I meant by "then set it back to its original value, then draw the rest of your GUI". Doing so ensures that the rest of your GUI gets drawn with the original (not upside down) GUI.matrix.
Also note that GUIText objects are likely only there for backwards compatibility reasons. They were the first GUI-stuff Unity Tech created. The GUI system was introduced later and is meant to supercede the GameObject versions of GUI elements.
I've added a code snippet that demonstrates how to draw only one thing with a changed GUI.matrix.
Answer by tomekkie2 · Jun 21, 2012 at 01:45 PM
Here is the code to put in the OnGUI function to do that:
var matrixBackup:Matrix4x4 = GUI.matrix;
var thisAngle:float = 180;
var pos:Vector2 = Vector2(Screen.width/2, Screen.height/2);
GUIUtility.RotateAroundPivot(thisAngle, pos);
//all to be rotated put here
GUI.Label(new Rect(Screen.width/2-100, Screen.height/2-50,200,50), "Upside down");
//end of rotated
GUI.matrix = matrixBackup;
Your answer
Follow this Question
Related Questions
Changing a GUILabel text SIZE 3 Answers
Why aren't asian fonts rendering dynamically? 0 Answers
Problem with GuiFont - Not appearing 0 Answers
Color.white not so much white... 3 Answers
Alpha not working in GUITex 0 Answers