I want to pan my map when the user drag-and-drops the map of my game with his mouse. I have written this script to do so:
if (Input.GetMouseButton (0)) {
Vector3 currMousePosition = Input.mousePosition;
Vector3 mouseDelta = prevMousePosition - currMousePosition;
Vector3 newCamPos = new Vector3(
Mathf.Clamp(transform.position.x + mouseDelta.x * MouseScrollSpeed * Time.deltaTime, ScrollBottomLeft.x, ScrollTopRight.x),
transform.position.y,
Mathf.Clamp(transform.position.z + mouseDelta.y * MouseScrollSpeed * Time.deltaTime, ScrollBottomLeft.z, ScrollTopRight.z));
transform.position = newCamPos;
}
In addition, I have several GUI-Buttons appearing on the screen. What happens now is that when I position my mouse over one of those elements, mouse-down over it and move the mouse, my camera script is triggered. How can I determine if the mouse is over any GUI-Element or not and if so avoid scrolling! I’m looking for something like
if (Input.GetMouseButton (0) && <mouseNotOverGuiElements>) { <scroll> }