# GUI Scale and Rotate

Hell everyone
i Have 2 codes 1 to rotate my guis and the other to scale them. Both work great alone but when i put them together the GUI’s just rotate and dont scale
here are my Codes

The Scale

``````function OnGUI()
{
if(GUI.Button(ResizeGUI(Rect(470, 225, 100, 50)), "Settings"))
{

}
}

function ResizeGUI(_rect : Rect) : Rect
{
var FilScreenWidth = _rect.width / 800;
var rectWidth = FilScreenWidth * Screen.width;
var FilScreenHeight = _rect.height / 600;
var rectHeight = FilScreenHeight * Screen.height;
var rectX = (_rect.x / 800) * Screen.width;
var rectY = (_rect.y / 600) * Screen.height;

return Rect(rectX,rectY,rectWidth,rectHeight);
}
``````

The rotation

``````private var rotAngle : float = 90;
private var pivotPoint : Vector2;

pivotPoint = Vector2(Screen.width/2,Screen.height/2);
GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
if(GUI.Button(ResizeGUI(Rect(470, 225, 100, 50)), "Settings"))
{

}
``````

If anyone one knows how to make them both work please answer me im so frsutrated D:
Thank You

skullbeats1

You can use the GUI.matrix instead to do the scaling and rotation at the same time:

You basically assign to it a matrix created with this static method:

Here is an example:

``````	Matrix4x4 transformation = Matrix4x4.TRS(
Vector3.zero,
Quaternion.identity,
Vector3.one);

void OnGUI() {
// We need to assign the GUI matrix before GUI controls are shown.
GUI.matrix = transformation;

if (GUI.Button(new Rect((Screen.width - 250) / 2, (Screen.height - 100) / 2 - 55, 250, 100), "TRANSFORM GUI")) {
transformation = Matrix4x4.TRS(
new Vector3(-Screen.width * 0.2f, -Screen.height * 0.7f, 0),	// move the GUI a little to fit the transformed controls in the screen
Quaternion.Euler(0, 0, 15),	// rotate 15 degrees clockwise around Z, because controls are in XY plane
new Vector3(2, 2, 1));	// scale GUI x2 times in X and Y
}

if (GUI.Button(new Rect((Screen.width - 250) / 2, (Screen.height - 100) / 2 + 55, 250, 100), "NORMALIZE GUI")) {
transformation = Matrix4x4.TRS(
Vector3.zero,
Quaternion.identity,
Vector3.one);
}
}
``````