- Home /
How do I set a new Vector 2 for a GUI.Utility RotateAroundPivot?
Gda'y all,
I have made a simple Rotating Texture2D. But the needle pivot changes depending on screen size..
I have researched for a whilst now and everyone mentions Matrix4x4 backup.
I tried to implement it (seemed easy was only 2 lines of code)..but it done nothing? Its fine on the resolution it is, but not on smaller resolution.
Does matrix backup work? and can you help me implement it please?
I know it's because of the needle pivot rect, I don't quite know the solution.
Help would be greatly appreciated, cheers :)
Tim.
var native_width : float = 1280;
var native_height : float = 720;
var tachosystemon : boolean;
var needleTexture : Texture2D;
var compassTexture : Texture2D;
var rotAngle : float = 0;
var pivotPoint : Vector2;
var needleRect : Rect;
var compassRect : Rect
function OnGUI (){
var rx : float = Screen.width / native_width;
var ry : float = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
GUI.skin = dials;
if(!tachosystemon && GUI.Button (Rect (r1, r2, r3, r4),"DIALS")){
tachosystemon = true;
}
else if(tachosystemon &&GUI.Button (Rect (r1, r2, r3, r4),"DIALS")){
tachosystemon = false;
}
if(tachosystemon){
GUI.DrawTexture(compassRect, compassTexture);
GUIUtility.RotateAroundPivot(rotAngle, pivotPoint);
GUI.DrawTexture(needleRect, needleTexture);
}
}
If by "matrix backup" you mean to back it up and restore it after messing with RotateAroundPivot, sure:
$$anonymous$$atrix4x4 backup$$anonymous$$atrix=GUI.matrix;
//do your stuff
GUI.matrix=backup$$anonymous$$atrix;
As to the resolution problem, if it's what I'm facing, it seems that for anything outside of a 4:3 aspect ratio the pivoted texture's dimensions will be skewed because it seems that the changing resolution is factored into the GUI-drawn textures before the rotation matrix is applied; hence, if you have a tall texture rotated 90 degrees to the right, squishing the game window vertically in the editor will actually make it get shorter horizontally, screwing up its relative post-rotated dimensions. I'd be all ears to a solution to that myself.
I am having a lot of trouble with GUIUtility.RotateAroundPivot. Could you please give me a hand? Thank you! Here is my link
Your answer
![](https://koobas.hobune.stream/wayback/20220613122454im_/https://answers.unity.com/themes/thub/images/avi.jpg)