How to set a GUI.Box at the center of a gameObject

I am creating a GUI.Box in a C# script attached to a gameObject.

I’ve tried:

    GUI.Box(new Rect(gameObject.transform.position.x, gameObject.transform.position.y, 50, 50),ShipAmt.ToString(), PlanetGUI);

And that just puts it in the top left corner of the screen

Simple way, it’s use function WorldToScreenPoint(), which transforms position from world space into screen space. Attach this script at your object(write on CSharp):

 void OnGUI() {
  //Use Main Camera and get position current object, but point position is pivot point
  Vector3 screenPos = Camera.main.WorldToScreenPoint(this.transform.position);
  //And size box, for example 100x50
  GUI.Box(new Rect(screenPos.x, Screen.height - screenPos.y, 100, 50), "myBox");
 }

I hope that it will help you.