How to use Input.GetMouseButtonDown() but it doesnt get called if the user clickes a button.

I have a game that uses Input.GetMouseButtonDown() to do things. When I click a button now, using Unity UI system, it still calls Input.GetMouseButtonDown(). Is there any way I can avoid this?
Thanks

You could use a flag, something like

if(Input.GetMouseButtonDown(1) && playerIsInGame == true){

//do your function code here normally

}

Then, when your setting up the code on your buttons click events, you can just disable the playerIsInGame.

Alternatively, if this UI is like a pop up (for example, a pause screen), then you could also do a trigger to check if your pause screen canvas is turned on before carrying out your click event.

There is also another, very simply way, but for some reason, its not coming to mind right now… Though maybe one of those 2 alternatives will work out for you.