How do I cancel player Input when pressing a pause button?

Hello. Now I’m doing a simple Flappy Bird-like game, which has a simple PlayerController class like this:

if (Input.GetMouseButtonDown (0) || Input.GetButtonDown (“Jump”)) {
// Player flying up code
}

I also add a pause button. In the Button component, I hook a pause function with On Click (). Everything works fine, except when I play the game and press the pause button, player also flies up.

What is a good way to cancel player input when pressing a pause button? Thank you.

You could put a public bool in your player controls and set it to true when the mouse is over the pause button and false when it leaves using OnMouseEnter and OnMouseExit.

If the bool is true in the player control then ignore inputs.

1 Like

Thank you. OnMouseEnter and OnMouseExit don’t work for me, so I use Pointer Enter and Exit of Event Trigger with public bool instead and it work now.

Does anyone know whether Event Trigger will work with touch screen on mobile devices?

The way I do that on a PC version of the game is, I just disable the player controls script attached to the player.

var player : name-of-player-controls-script-attached-to-player

Then when I want the player controls disabled I do:

player.enabled = false;

On Mobile using Pointer Events with a Canvas / EventSystem I do it a completely different way.

I have a variable of:

var buttonMoveLeft : UI.Image;

Then when I want the touch button disabled I do:

buttonMoveLeft.raycastTarget = false;

I do this for all the touch buttons and it works fine for me. Someone else may probably have a better method but this works fine for me.

3 Likes