Cannot click UI button when using First Person controller

I am using the First Person script from this page:

However, I am adding a UI button which can be clicked. So in order for the player to be able to click the button, they have to press escape to release the mouse pointer. But when you then try to click the button, the ‘click’ event is never fired - I think it does mouse down, but never makes it to mouse up - because it just starts controlling the first person movement again.

How can I ensure that the button can be clicked in a scenario like this?

Hi @steve_wk,

So this is a common issue when using app wide mouse/touch events that listen for input from the whole app window. Which is the case with the first person movement tutorial.

What I usually do is create a global var in my UI input handling script, so when there is a button event fired, I set that global var equal to true.

I then listen to that var in all mouse start, mouse move and mouse end methods in the movement script, and if it’s true I don’t allow the script to move forward with grabbing the pointer and locking it.

Aaaah, ok makes total sense now.

Thanks, got it working in a similar way to your suggestion. Thanks so much!

1 Like