- Home /
Question by
hedi.d · Oct 19, 2014 at 03:30 PM ·
hotcontrol
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 :)
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;
}
Comment
Answer by zharik86 · Oct 19, 2014 at 06:03 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613165431im_/https://answers.unity.com/themes/thub/images/avi.jpg)