UI Button and character actions

I’m making an endless runner using 2D Toolkit for sprites and also for UI. I have my main character that checks in Update() for a Input.GetKeyDown(KeyCode.Mouse0), if that happens, it triggers the Jump() function.

The issue appears when I added UI elements. When I press a button, the button triggers an action but also the main character jumps. I tried to put a bool on the button action, something like “buttonPressed = true”, and inform the main character script. Then, in Update() I check for Input.GetKeyDown(KeyCode.Mouse0) && buttonPressed == false. But this doesn’t work because apparently the button action and the character jump are triggered at the same time. So, how can I do to avoid character jumping when Im pressing a button?

You can try to modify Script Execution Order in Project Settings or just add a collider that follow your camera, use OnMouseDownfunction to call jump, raycast will do the rest of the job.