Center GUI.Window when using GUI.matrix

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) ); 
		
	}

I figured it out. As always, one minute after posting for help. Don’t you just hate that? :slight_smile:

I was calculating the center according to the current screen width (Screen.width) and height (Screen.height).
However, I should have calculated the center according to the native screen resolution.

void OnGUI() {
	GUI.matrix	= MyGUI.GetMatrix();
	GUI.Window(0, new Rect(nativeScreenWidth / 2 - 300, nativeScreenHeight / 2 - 200 , 600, 400), DrawWindow, "");
}
	
private void DrawWindow(int id) {
	// Here goes everything inside of my window
}