Aligning To the Right Top Corner of the Screen!

Hi, how do i change this script from 2D tutorial to align the GUI on the top right side.
This works beautifully when switching between Fixed Game Dimensions and Free Aspect Full Screen
the gui always stays nicely in the top corner… how do i tweak it to do the same on the right top corner!? :slight_smile:


private var windowRect = Rect (20, 20, 250, 50);
function OnGUI () {
// Make a window
windowRect = GUILayout.Window (0, windowRect, DoControlsWindow, “Controls”);
// Align
windowRect.x = Mathf.Clamp (windowRect.x, 0.0, Screen.width - windowRect.width);
windowRect.y = Mathf.Clamp (windowRect.y, 0.0, Screen.height - windowRect.height);
}

private var windowRect = Rect (Screen.width - 250 - 20, 20, 250, 50); // 250 is your window width

btw the ‘Align’ part doesn’t seem to align, but instead making sure that you don’t drag the window out of the visible screen. :wink:

works perfectly! thank you…
yes i see that :slight_smile: