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;
}
}
}
}