C# Gui.Box Scaling/ positioning with resolution

I am using a gui.box, with a custom guistyle, but when I change resolutions the gui is all off position, and scaled differently, sometimes it even dissappears on different resolutions. Any help would be greaty appreciated.

using UnityEngine;
using System.Collections;

public class Inventorygui : MonoBehaviour {
bool render;
public bool use;
public GUIStyle inventory;

// Use this for initialization
void Start () {

}

void OnGUI()
{

if(render){
GUI.Box(new Rect(Screen.height / 2, Screen.width / 2,Screen.width / 2, Screen.height / 2),“”,inventory);

}
}

void ToggleWindow()
{
render = !render;

}

void Update()
{
if (Input.GetKeyDown(KeyCode.I))
{
ToggleWindow();
}
}

Hi,

You have the width and height in the wrong places for the position, it should read:

new Rect(Screen.width/ 2, Screen.height/ 2,Screen.width / 2, Screen.height / 2)

HotFuzz,

Also, if it is important to have the GUI elements scale with different resolutions, then you should check out GUI.Matrix. This thread should have the info you’d need.

Cheers!
Cahman