HUD/GUI element positioning

Unity noob here.

In my game I have code in my OnGUI () that draws Rects on the screen for inventory slots on the HUD. This works fine, they sit and scroll with screen as they should.

Rect slotRect = new Rect(xpos, Ypos, 30, 30);
GUI.Box(slotRect, "", skin.GetStyle("Slot"));

However when I maximize the screen, the slots no longer sit where they should, instead they keep their position and size so end up floating in the middle of the play area.

How can I solve this so that they always position and size relative to the screen?

You have accecss to the variables Screen.width and Screen.height. Use these to make your GUI elements always draw in positions that are relative to screen space. For example, you can center a Rect no matter the resolution with

Rect rect = new Rect(Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100);