Re size GUI.box and GUI.Button

This is my code that I wrote. My question is How do I get it it re size when I change off of Free Aspect. For example 1024 X 768 shows Like how I have it set up in the scene. but when I change to 1920 X 1080 All my GUI is off center. I have done a google search but so far I have not been able to get anything to work. If you have a link that will help me I can research it on my own I have not issue with that. \

Also I have many topics on how to re scale a texture that is attached to a object. But this is not my case. I am drawing my GUI from code. As of now the only way I see the GUI in my game window is when I hit play.

using UnityEngine;
using System.Collections;

public class MyGUI : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	// Void OnGUI() is the function for your Graphic user Interface (GUI)
	void OnGUI(){

		// Make a backgroud for the button.
		// GUI.box = A box is created / new Rect() = A new Rect is created / new Rect(10(top left), 10(top right), 100(width), 100(height)) In pixels.
		// "Main Menu" is what will be displayed at top of the box.

		GUI.Box (new Rect(460, 10, 100, 200), "Main Menu");

		// Make a button that can be clicked on.
		// Debug.Log() creates text in your console.
		// Application.LoadLevel(); Takes you to what ever scene that you tell it to. scene number goes in () after LoadLevel.

		if (GUI.Button (new Rect (470, 55, 80, 20), "Options")) {
			Debug.Log ("Options");
			//Application.LoadLevel(1);
			}
		if (GUI.Button (new Rect (470, 75, 80, 20), "Credits")) {
			Debug.Log ("Credits");
			//Application.LoadLevel(1);
		}
		if (GUI.Button (new Rect (470, 95, 80, 20), "Exit")) {
			Debug.Log ("Exit");
			//Application.LoadLevel(1);
		}
		if (GUI.Button (new Rect (470, 35, 80, 20), "New Game")) {
			Debug.Log ("Loading New Game");
			Application.LoadLevel(1);
		}


	}
}

This should help :

function OnGUI () {
GUI.Button (Rect (0,0,100,50), "Top-left");
GUI.Button (Rect (Screen.width - 100,0,100,50), "Top-right");
GUI.Button(Rect(Screen.width /2 - 50, Screen.height/2 - 50,  100, 50),"Center");
GUI.Button (Rect (0,Screen.height - 50,100,50), "Bottom-left");
GUI.Button (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-right");
}

Will this work in C#?

Yeah, you’ll just have to tweak it a little :

void OnGUI () {

GUI.Button (new Rect (0,0,100,50), "Top-left");

GUI.Button (new Rect (Screen.width - 100,0,100,50), "Top-right");

GUI.Button(new Rect(Screen.width /2 - 50, Screen.height/2 - 50,  100, 50),"Center");

GUI.Button (new Rect (0,Screen.height - 50,100,50), "Bottom-left");

GUI.Button (new Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-right");

}

Ok I created this Script and I see buttons at each corner of my Screen. They also stay that way when I change my Screen size. But I am not sure I understand why this is. Then only difference i can see is your doing Screen.width /2 in two of the lines of code. Is this what keeps everything in the same spot?

Yeah. Using Screen.width Screen.height is more reliable than hard-coding the x y screen positions.

Yep This helped a alot thank a ton.