how to get Gui in OnGUI function to resize with the window?

Hi. I have an inventory gui set up, but it only works with a specific resolution. The size and position doesnt change with the screen. For example, it works on a large window, but when this window is shrunk real small it then takes up the entire window. Is there any simple way to adjust for this, so the GUI’s size is respective to the size of the game window?

Thank, any help is appreciated

Probably, for a start you need to try to use GUI.matrix. Simply set coefficients of change of a display resolution from what you took as a basis. Example of use see below(write on CSharp):

 void OnGUI() {
  //write your GUI elements for one screen resolution, for example, 1280x720
  float scalex = (float)(Screen.width) / 1280.0f;
  float scaley = (float)(Screen.height) / 720.0f
  GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(scalex, scaley, 1);
  //and, for example, I create label with text
  GUI.Label(new Rect(0, 200, 600, 100), "Some text");

I hope it to you will help.