I've been working on a project where i need to fulfill the following behaviors:

1) when clicking anywhere in the screen the character should do something

2) there are some buttons so except when you click a UI Button (which is the pause button in this case )you should move.

So, the problem is since the character behavior is in the Update Function when the player clicks on the pause button unity executes first the Update function, moves the character and pauses after that.

Is there any way to pause tell Unity to execute first the OnClick function inside the UI Button than the Update function?

What i tried was this but it didn't work:

1)do 2 booleans click1,click2;

2)click1 equals true when we click anywhere in the screen

3)click2 equals true when we click on the UI Button

4)then i do something like this so unity should wait 1 frame before executing the movement when click1 == true && click2 == false, we execute the behavior else that means we hit the UI button.

This is how it looks in actual code

void Update()
    if (platform == RuntimePlatform.WindowsEditor || platform == RuntimePlatform.WindowsPlayer)
                    if (v_click1 == true && v_click2 == false)
                        if (v_inGround)
                            v_changeGravity = ChangeGravity();

                        v_click1 = false;//reset the value
                    if (Input.GetMouseButtonDown(0))

                       v_click1 = true;

As you can see i have logged some numbers and Number 4 is not there but it displays when Onclick function sends the message from the UI Button.

The order this is taking is the following:


3 we detect a click which is in the button but we dont know that

2 we do the behavior(movement)

4 the function for pause gets called...

So, this is basically the problem is there any way to do this or should i just try not using the UI?

if the question is too confusing i will try to rephrase it haha.



1 Answer 1


You can put an empty button (button without sprite) in background of screen size and ui buttons above that.

  • \$\begingroup\$ oh yeah, do this button without using the UI haha thanks \$\endgroup\$
    – Makenshi
    Jan 23, 2016 at 18:32

You must log in to answer this question.

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