Centering Inventory GUI

Hi guys, this is what I have:

and the inventory is located in the top left corner… any ideas how to center it?

You first get the center coordinates of the screen by Screen.width/2, that brings the left corner to the center, to make it central you substract half the width of your window.

x = Screen.width/2 - windowWidth/2;
y = Screen.height/2 - windowheight/2;

If you don’t use a window, you can just set it as reference variables and add them to every x/y coordinate.
Like:
`

xRef = Screen.width/2 - windowWidth/2;
yRef = Screen.height/2 - windowheight/2;
for (int y = 0; y < slotsY; y++)
{
   for(int x = 0; x < slotsX; x++)
   {
       Rect slotRect = new Rect (xRef + x * 50, yRef + y * 50, 50, 50);
       GUI.Box (slotRect, "", skin.GetStyle("Slot"));
       slots _= Inventory*;*_

`
I recommend you look into a window tutorial.

You can read the current screen size with Screen.width and Screen.height. This means you can take the Screen.width, divide it by 2 to get the pixel from the left border to the center, and subtract half of the width of the GUI element from it, and use that value as the pixel coordinate for your GUI element.

int boxSize_x = 32;
int boxSize_y = 50;
int pos_x = Screen.width / 2 - boxSize_x / 2;
int pos_x = Screen.height / 2 - boxSize_y / 2;

Rect boxRect = new Rect(pos_x , pos_x , boxSize_x , boxSize_y );