GUI Buttons?

Hi, is there any script or way for buttons to keep locked to the screen size (no understandable way to put it). I have been testing my game in half screen and finally got the buttons right. i finally tested in full screen and the buttons are in strange positions, the same in which they are in half screen. the EXACT same.

That’s because you aren’t using Screen.width and Screen.height to place them.

For instance, if you wanted the button to always start 100 pixels left of the center of the screen, go 200 pixels right, and go 200 pixels down, you’d do this: GUI.Button(Rect(Screen.width * .5 - 100, Screen.height * .5, 200, 200), “Content”);

If you want your buttons to scale with the screen as well, you could add a scale factor to the GUI. For instance in GargerathSunman’s example, you could do this (untested):

private Matrix4x4 guiScale;

public void Awake()
{
    guiScale = Matrix4x4.Scale( new Vector3( Screen.width / 640.0f, Screen.height / 480.0f, 1.0f ) );
        // We're testing the GUI in a 640 x 480 resolution
}

public void OnGUI()
{
    GUI.matrix = guiScale;

    GUI.Button(Rect(Screen.width * .5 - 100, Screen.height * .5, 200, 200), "Content");
}