title: Local and World Coordinates of GUI elements on Game Object
body: <p>I have a <code>GameObject</code> that is created on screen, in Unity 2D mode.</p>
  
  <p>The co-ordinates of the <code>GameObject</code> is <code>(3, 3)</code>. In the script attached to the <code>GameObject</code>, I have the following <code>OnGUI()</code> method:</p>
  
  <pre><code>void OnGUI() {
      if(GUI.Button(new Rect(renderer.bounds.min.x, renderer.bounds.min.y, renderer.bounds.max.x, renderer.bounds.max.y), "")) {
          Debug.Log ("My Position: " +  this.transform.position.x + ", " + this.transform.position.y);
      }
  }
  </code></pre>
  
  <p>But when I run the Unity project, the <code>GUI.Button</code> is created at the left top corner of the screen, instead of exactly covering the <code>GameObject</code>. Is the reason because of the difference of local and world co-ordinates?</p>
  
  <p>How do I create a <code>GUI.Button()</code> exactly over the Game Object ?</p>
  
  <hr>
  
  <p><strong>Update:</strong> After reading @0Andrea's answer, I updated the code. Problem persists:</p>
  
  <pre><code>private Vector3 worldPos;
  
  void Start () {
      worldPos = Camera.main.WorldToViewportPoint(gameObject.transform.position);
  }
  
  void OnGUI() {
      if(GUI.Button(new Rect(worldPos.x, worldPos.y, 1, 1), "")) {
          Debug.Log ("My Position: " +  this.transform.position.x + ", " + this.transform.position.y);
      }
  }
  </code></pre>
  
  <p>The <code>GUI.Button</code> is still locating at left top corner of the screen, instead of over Game Object. What did I miss?</p>