- Home /
GUIUtility.RotateAroundPivot isn't working
I'm having trouble trying to get my GUI object to rotate around its central point.
its meant to be an arrow that circles around a mini-map pointing towards the objective.
I'm using Unity 3.4.0f5
The arrow shows and is positioned correctly but it just wont rotate.
"rotAngle = GameObject.Find("ObjectiveWatch").GetComponent(WatchObjective).direction;" is fed by a Euler Angle.
var minimapArrow : Texture2D;
private var rotAngle : float = 0;
private var pivotPoint : Vector2;
function OnGUI() {
GUI.depth=149;
GUI.Label (Rect ((Screen.width) - 226, (Screen.height * 0.20) + 7, 202, 202), minimapArrow);
rotAngle = GameObject.Find("ObjectiveWatch").GetComponent(WatchObjective).direction;
//Debug.Log("direction = " + rotAngle);
pivotPoint = Vector2((Screen.width) - 327, (Screen.height * 0.20) + 108);
GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
}
i tried that a few days ago, but it didn't work for me either, no matter what code i tried. the way i see it .rota$$anonymous$$roundpivot is for a singular, not a constant rotation.
one way around that is to put the texture you want to rotate on a mesh and rotate that.
but it's not really like some sort of flowing rotation.. it's one adjustment each frame.. the unity scripts reference does the same thing. in fact this was almost a copy from there :\
fixed it!!
var $$anonymous$$imapArrow : Texture2D;
private var rotAngle : float;
private var pivotPoint : Vector2;
function OnGUI() {
var matrixBackup:$$anonymous$$atrix4x4 = GUI.matrix;
rotAngle = GameObject.Find("ObjectiveWatch").GetComponent(WatchObjective).direction;
pivotPoint = Vector2((Screen.width) - 125, (Screen.height * 0.20) + 100);
GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
GUI.depth=149;
var myRect:Rect = Rect((Screen.width) - 223, (Screen.height * 0.20) + 4, 202, 202);
GUI.DrawTexture (myRect, $$anonymous$$imapArrow);
GUI.matrix = matrixBackup;
}
Answer by Tommynator · Sep 30, 2011 at 09:39 AM
A classic mistake, you have to draw you arrow image AFTER changing the rotation matrix of the GUI. Make sure to set the matrix to identity after the operation.
//do the rotation
GUIUtility.RotateAroundPivot(rotAngle, pivotPoint);
//draw image
GUI.DrawLabel(Rect(Screen.width - 226, (Screen.height * 0.20) + 7, 202, 202), minimapArrow);
//reset
GUI.matrix = Matrix4x4.identity;
Consider using DrawTexture() instead of Label() as it's a bit more efficient if you just want to draw a Texture2D. (You have to set the dimensions manually though as it's not keeping the aspect ratio automatically)
thank you, yeah i found the solution from Lee Gibsons response, and realised that drawing before rotating was my mistake, but it is all fixed now =D
again, thank you
Answer by LeeGibson · Sep 30, 2011 at 08:27 AM
i find it also hard to believe that it's not possible to rotate a gui texture.
maybe this might help: http://forum.unity3d.com/threads/36951-Rotate-A-GUI-SPrite-element-texture
Answer by fitzy.89 · Sep 30, 2011 at 11:41 AM
Thank you Lee Gibson!!
thanks to you i managed to get a script that worked for rotating the minimaps arrow with ease!!
the most fiddly part is positioning the pivot point.
var minimapArrow : Texture2D;
private var rotAngle : float;
private var pivotPoint : Vector2;
function OnGUI() {
var matrixBackup:Matrix4x4 = GUI.matrix;
rotAngle = GameObject.Find("ObjectiveWatch").GetComponent(WatchObjective).direction;
pivotPoint = Vector2((Screen.width) - 125, (Screen.height * 0.20) + 100);
GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
GUI.depth=149;
var myRect:Rect = Rect((Screen.width) - 223, (Screen.height * 0.20) + 4, 202, 202);
GUI.DrawTexture (myRect, minimapArrow);
GUI.matrix = matrixBackup;
}
lol its funny because i posted up this answer before any of the other things were up but it has only shown up now =D
@fitzy.89: That's because you have not enough karma. Afaik you need at least 15 karma to directly post questions / answers. It has been implemented to prevent spammers from registering fake accounts. All things posted from people below 15 karma will end up in the moderation queue. Every user with 1000+ karma can allow those posts but we have to find the time ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220612231739im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Limiting object rotation using GUI.Buttons? 1 Answer
GUI Button not working...but the the script is correct... 2 Answers
Bind horizontal scrollbar to camera control 1 Answer
how can i flip my scoredisplay var guitext so that it appears upside down? 0 Answers
Why isn't my Gui showing up at all? 1 Answer