I've a classic

void Update() {
   if(Input.GetMouseButtonDown (0)) 

What i want to do is that if I click on a UI button , the Fire() routine not will be called.

How to do to say Unity if InputGetMouseButtonDown(0) && !UI clicked ?


2 Answers 2


So, first, stop using Input.GetMouseButtonDown(0), use Input.GetButton("Fire1"). This allows your player to remap the controls. It won't fix your problem, but this is still something you should do.

Onto your problem, you have a few options:

  • When the UI is up, set some global variable (eg. gamePaused) that when true, your game logic doesn't execute. This includes shooting.
  • Ask the event system: EventSystem.current.IsPointerOverGameObject()
  • Check if your mouse is in a region of the screen (eg. over/not over the UI) and if over the UI, don't fire.
  • \$\begingroup\$ First, Thanks for your answer. I'm trying with EventSystemManager.currentSystem.IsPointerOverEventSystemObject() but it seems it didn't recognize. Do I need to add "using" something ? I've also added "using UnityEngine.EventSystems" but not works \$\endgroup\$
    – stighy
    Jan 17, 2018 at 20:05
  • 3
    \$\begingroup\$ @stighy Sorry, old code. You do need a using (using UnityEngine.EventSystems), but the current method call is EventSystem.current.IsPointerOverGameObject(), it's been renamed at least once if not twice. \$\endgroup\$ Jan 17, 2018 at 20:11

Another option is that when you click on the UI button, you should enable / disable the script that has the Fire().


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .