Problems with Screen.width (C#)

First off, I lost all the files for my game and have to restart from scratch. I’m using mostly C# this time since that’s the script I’m learning to work with in my video game design class.
Anyways, I’m trying to get a GUI toolbar to be positioned in the center of the screen, no matter what the aspect is. Here’s my code:

using UnityEngine;
using System.Collections;

public class GameOverGUI : MonoBehaviour {

	//sets the toolbar
	private int toolbarInt = 0;
	private string[] toolbarStrings = {"Load Game", "Main Menu", "Exit"};
	void OnGUI(){
		toolbarInt = GUI.Toolbar (new Rect(Screen.width/2, Screen.height/2, 300, 30), toolbarInt, toolbarStrings);
	}
}

Now, the buttons should be positioned in the center of the screen, right? Well they’re positioned more to the right than I would like them to be.
[15617-slightly+to+the+right.png|15617]

Any help with this problem is appreciated.

Based on your code, the toolbar would start at the center of the screen. Remember, when you are declaring a new Rect() the parameters are set up like this:

Rect(StartPointLeft, StartPointTop, Width, Height);

So declaring it like this

new Rect(Screen.width/2, Screen.height/2, 300.0f, 30.0f)

Will start a 300x30 pixel Rect at the center of the screen and it will extend to the right of the screen center.

To get everything centered you need to subtract half the width of the rect from the screen center to push it left and half the height of the rect from the screen height to push it up. Having your code like this will perfectly center your toolbar:

using UnityEngine;
using System.Collections;
 
public class GameOverGUI : MonoBehaviour 
{
 
    //sets the toolbar
    private int toolbarInt = 0;
    private string[] toolbarStrings = {"Load Game", "Main Menu", "Exit"};
    void OnGUI(){
       toolbarInt = GUI.Toolbar (new Rect(Screen.width/2 - 150.0f, Screen.height/2 - 15.0f, 300.0f, 30.0f), foolbarInt, toolbarStrings);
    }
}