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.