Ignore clicks on UI in script/detect when the mouse is over UI

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?

Hi Guys
As u said “IsPointerOverGameObject” is the best way to solve this ,
I think u didn’t use it well so u thought it can’t solve your problem,

I had a top-down shooter game and the same problem,
I did manage to solve that problem with : “IsPointerOverGameObject”

but its so complex to use and unity-manual didn’t mention it well ,
if u use it wrong it will give u wrong answers and your code won’t work,

there are 3 conditions :

if u are in Editor and using mouse for your input you should use this :

 if(EventSystem.current.IsPointerOverGameObject ( 0 )
    {
     doit = false;
    }

if u build the program for android it should like this , if not it wont work:

   if(EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
    {
     doit = false;
    }

if u are in Editor and using remote :

  if(EventSystem.current.IsPointerOverGameObject(-1))
    {
     doit = false;
    }

for android u should put these if statement only in “touch began” as said in unity manual"

  if (Input.GetTouch(0).phase == TouchPhase.Began)
            {
    }

these number may have been changed in different positions since i have different version of unity but i should give u an idea about how hard this works on different Platforms;
any way be sure that this will work, just need a little change .,.,

Cuttlas

I have the exact same problem and an answer would be nice.