GUI Idiot Here and Needs Help

Ok I have a few questions:

a) When code has this: (new Rect(0,0,0,0));

That really means: (new Rect(width,height,total width, total height)); correct?

b) what does total height and total width stand for?

c) If my screen resolution is 1366x768 what would be dead center if I was writing GUI for a label?

Here is the code I have so far for C if it helps (Also if you see anything wrong with it please point it out):

using UnityEngine;
using System.Collections;

public class TitleScreenGUI : MonoBehaviour {
	
	private float originalWidth = 1366.0f; //My screen width
	private float originalHieght = 768.0f; //My screen height
	private Vector3 scale;
	
	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnGUI () {
		scale.y = Screen.height/originalHieght; //Calculates Verticle Scale
		scale.x = Screen.width/originalWidth; //Keeps ratio based on verticle scale
		scale.z = 1;
		
		var svMat = GUI.matrix; //save current matrix
		GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale); //Sets up new matrix
		
		GUI.Label(new Rect(650,384,1366,768), "Press Enter");
		
		GUI.matrix = svMat; //restore original matrix
	}
}

I believe it’s…

A. The other way around

B. Screen size

C. (Screen.width/2)-offset.width.Of.Label/2,(Screen.height/2)-offset.height.Of.Label/2,label.width,label.height

Hope this helps:

A: The Rect constructor means the following -
new Rect(LeftStartingPoint, TopStartingPoint, Width, Height);
Creating doing this

GUI.Label(new Rect(0.0f,0.0f,100.0f,100.0f), "Press Enter");

Will result in a 100x100 pixel label starting in the upper left corner of the screen.

B: See above, the last two parameter (width and height) represent the size in pixels of the Rect you are creating.

C: Using the above example, a perfectly center 100x100 pixel label would be constructed as follows:

// Create a 100x100 pixel Label at the screen's center
// Note that I use multiplication here instead of division
// because it takes less time to process...just a habit
// I picked up
GUI.Label(new Rect(Screen.width * 0.5f - 50.0f, Screen.height * 0.5f - 50.0f, 100.0f, 100.0f), "Centered on Screen");

Alternatively, if you want to do something like a label that is one quarter of the screen and centered you could do something like this:

// Capture floats that represent one quarter
// of the screen width and height 
float quarterWidth = Screen.width * 0.25f;
float quarterHeight = Screen.height * 0.25f;

// Create our Label using quarterWidth and
// quaterHeight as the left and top start points
// respectively, as well as the size of the label
GUI.Label(new Rect(quarterWidth, quarterHeight, quarterWidth, quaterHeight), "PressEnter");

As far as your code is concerned everything looks fine for an GUI that can scale to any resolution. I did notice that your label covers the entire screen though and I’m not sure if that is what you intended.