Mysterious Rect problem

Hello. I have a crazy problem with Rect().

When I use

GUILayout.Window(0, Rect(Screen.width/2-75,Screen.height/2-75, 150, 100) , LoginWindow, "Loginversuch");

The window is in the center of the screen.

But when I define a variable with the same rect

private var windowRect = Rect(Screen.width/2-75,Screen.height/2-75, 150, 100);
GUILayout.Window(0, windowRect , LoginWindow, "Loginversuch");

Then only the width is centered but not the height (its over the top of the screen).

I cant find the problem. Please help, thanks again for your great help :)

EDIT. When I use (Debug.Log(windowRect) I get

(left:551,00, top:344,00, width:150,00, height:100,00)

Which seems to be fine, but why it doesnt apply the correct top value?


var windowRect : Rect = Rect((Screen.width/2)-75, (Screen.height/2)-50, 150, 100);
windowRect = GUILayout.Window(0, windowRect, LoginWindow, "Loginversuch");

In this case, I only added a space before Screen.height, parenth, and followed the basic unity example of a window found here:

also removed a space after 0, windowRect ,

Also, to be a bit more precise in center from top, it should be half your rect's height. so it should be Screen.height/2-50 I did this above, and also (not that its necessary) added in the additional parenth to find scrn height/width.

Give it a shot, lemme know :)