So I have a game where your camera is centered on a planet. You can click and drag to orbit the camera around the planet using the code
if (Input.GetMouseButton(0)){
velocityX += xSpeed * Input.GetAxis ("Mouse X") * distance * 0.005f;
velocityY += ySpeed * Input.GetAxis ("Mouse Y") * distance * 0.002f;
}
I then have panels, buttons, and scrollviews, etc, around the edges of the screen that the user can interact with, show, or hide. The problem is if you click and drag a slider in the UI or something, the camera orbits because it is just following the clicks. How do I detect if a click was over ANY UI element from my camera script and ignore it?
While the docs describe “IsPointerOverGameObject” as a way to detect if you are over a UI element in practice it returns true for any game object in the scene and is thus useless for this as at the very least you are clicking on the background stars object. OnPointerEnter/OnPointerEnter could be used to set a “isOverUI” variable to true on my camera script. However I would have to add a OnPointerEnter script to every UI element in my game, make sure they don’t trigger if the UI element is hidden, and have them store references to my camera script which seems like overkill. Is there no “PointerOverUI” function I can just call in my camera script?