Prevent Click Passing Through GUI Controls

I am creating a 2d endless runner game and i wanted a button to pause the game .The thing is that the click pass through the UI element causing the player to jump .I looked to find an answer to the similar topics but nothing worked so far . Here is the last attempt i did. Any help will be truly appreciated.

public class Pause : MonoBehaviour {

    public bool paused = false;

    public void pausedButton()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            paused = !paused;


            if (paused == true)
            {
                Time.timeScale = 0;

            }
            else if (paused == false)
            {
                Time.timeScale = 1;
            }

        }

    }
  }

I think you want to put that IsPointerOverGameObject on your jump maybe instead.

1 Like

You are right sir . I messed it up a little bit .Thank you so much for your help. It means a lot.

No problem, you’re welcome :slight_smile: