hotControl not working with GetMouseButton(0)

Greetings,

It seems the following code does not work. I can still click through my GUI window and move my camera. Please help :slight_smile:

`

   

if (Input.GetMouseButton(0) && GUIUtility.hotControl == 0)

      {
      
     var dx = Input.GetAxis("Mouse X");
      
    var dy = Input.GetAxis("Mouse Y");
      
      var dV =  new Vector3(-dx * 0.15f, -dy * 0.15f,0f);
      
         var newPos = Camera.main.transform.position + dV;
      
        newPos.x = Mathf.Clamp(newPos.x, minX, maxX);
      newPos.y = Mathf.Clamp(newPos.y, minY, maxY);
      
         Camera.main.transform.position = newPos;
      
   
      
 }

`

GUIUtility.hotControl use for button only. See docs about hotControl. When the user mousedown’s on a button, it becomes hot. For GUI.Window() you shall calculate independently a position of a mouse and check it. I hope that it will help you.