Individually rotate GUI Elements?

How would I go about rotating an individual GUI Element separate to the rest of the GUI, meaning rotate one thing but not others, is this even possible?

4 Answers

4

GUI functions can be rotated using GUI.matrix. GUIText and GUITexture elements can't be rotated. When using GUI.matrix in OnGUI, you should reset the matrix after the element you want rotated.

This is not right. You CAN rotate any GUI element individually. Its very simple, you rotate the whole GUI, draw your specific element and reverse the rotation. Look at this:

GUIUtility.RotateAroundPivot(clockNeedlRotation, Vector2(clockNeedlOffset.x, clockNeedlOffset.y+clockNeedl.height));
DrawImage(clockNeedlOffset, clockNeedl);
GUIUtility.RotateAroundPivot(-clockNeedlRotation, Vector2(clockNeedlOffset.x, clockNeedlOffset.y+clockNeedl.height));

Cheers,

Alexej

True only if the questioner is referring to UnityGUI. But that's not clear- there are also GUIText and GUITexture objects, which are not rendered by OnGUI. Eric's answer takes this into account (though he doesn't have code like you do.)

where did you find that script? or at least, what variables do you need to make, and what do they represent?

Or instead of removing the clock rotation reset the matrix. GUI.matrix = Matrix4x4.identity;

Hi,

There is a working script in the following question:

http://answers.unity3d.com/questions/3561/how-to-rotate-gui-textures

Bye,

Jean

UnityGUI elements (`GUI.*`) cannot be rotated at all, as far as I know. And the older GUIElement items probably can't be, either, since (even if they have a Transform component), they still occupy screen-space. So to answer your question, no, it's not possible, at least not without some third party script.

see question below, it is actually possible.