As long as I’m not using GUI.matrix to scale my GUI, I have no problems centering my GUI.Window on the screen.
As soon as I add the GUI.matrix to my OnGUI function, though, centering the window element does not work. The position is completely off.
Can anybody find out what is going wrong here?
void OnGUI() {
GUI.matrix = MyGUI.GetMatrix(); // CENTERING WORKS WHEN I LEAVE THIS OUT
GUI.Window(0, new Rect(Screen.width / 2 - 300, Screen.height / 2 - 200 , 600, 400), DrawWindow, "");
}
private void DrawWindow(int id) {
// Here goes everything inside of my window
}
Here is the Matrix function I’m calling:
public static Matrix4x4 GetMatrix() {
float rx = Screen.width / destWidth;
float ry = Screen.height / destHeight;
return Matrix4x4.TRS ( new Vector3(0, 0, 0), Quaternion.identity, new Vector3 (rx, ry, 1) );
}