accessing a GUI window's dimensions?

in my GUI im making everything proportional to the size of the screen its on, but for the smaller things like buttons it would seem easier if i could access the current window that the buttons are in’s width and height that change depending on the size of the screen.

what i want to know: is there a command for something like Screen.width/height, except its like window.width/height. ?

I’m not sure if this is what you’re talking about, but I’ll give it a shot.

When you make a call to GUI.Window, you pass in the x+y+width+height (stored in a Rect) as a parameter. Use that Rect.

how would i access that Rect? sry still getting used to all of this… im using c# if that matters any

From the scripting reference (with a comment slipped in):

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public Rect windowRect = new Rect(20, 20, 120, 50);
    void OnGUI() {
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }
    void DoMyWindow(int windowID) {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
            print("Got a click");

        // You can access windowRect here!
        // GUILayout.Label ("This window is " + windowRect.width + " wide and " + windowRect.height + " tall");
        
    }
}

thanks, but this didn’t really help that much, it wouldn’t re-size with the window it would make it really small and un-readable =\ i can post script so you know what im working with and im also having another problem but i want to get this one out of the way first

Rect winRect = new Rect(0, 0, 100, 100);

void OnGUI()
{
     GUI.Window(0, winRect, doWindow, "Title");
}

void doWindow(int id)
{
     // window code
}

float getWindowWidth()
{
     return winRect.width;    // this is, in essence, the width of the window
}

float getWindowHeight()
{
     return winRect.height;   // and this is the height
}

I’m not sure what you’re talking about, the only part you should pay attention to is the comments I added in.

Everything else should be replaced with your script.

Alternatively you can use KelsoMRK’s solution, but know that it doesn’t allow you to alter the width/height, or use it in multiple windows.

thanks for all the help, its all fixed now :slight_smile: and my GUI is finally finished… at least as far as it can go for now lol