Pause button script running after screen click

Hi everyone,

I have a mobile game where the only form of interaction is to tap the screen to make a ball jump.
There is also a pause button at the top of the screen with a pause menu that shows on click, but when you click it the ball jumps first then the pause menu shows.

The ball also has a script on it with a bool variable “StopMovement” set to false;

when the pause menu shows, on Start() it sets StopMovement to true but evidently this is happening after the jump.

I want the ball to not jump when i click the pause button.

I tried messing around with Edit → Project Settings → Script Execution Order
but it didn’t fix the problem.

Basically you have it set up so that anywhere that’s clicked on the screen, the ball jumps. That means that even if you click the pause button, the ball will jump since the script is listening to the whole scene. I saw in another thread about using ray casts to listen when the collider of the button was struck my the ray that was made from the click. I don’t exactly know how to use ray casts but here’s the documentation.

The only other way I would think about avoiding this is set up buttons around the background in the places where the pause button isn’t, but that seems much more tough and time consuming than using the rays.

Could you show me some code?
I am assuming that you use

Time.timeScale = 0

To pause the game.
You could put an if statement on your code where it says:

if(ButtonIsPressed)
{
    //Your Jump Code
}

Simply add:

if(Time.timeScale == 1 && ButtonIsPressed)
{
    //Your Jump Code
}

EDIT:
If this doesnt work then let me know. I had an issue like this before but cannot recall how exactly I fixed it.