Pausing game

Hi, I have problem with my game for mobile devices. My player is jumping using touch screen (Input.GetMouseButtonDown(0)). Now, I wanted to do pausing button, but when I’m touching this button my player is jumping. How can I do this pause without jumping? This is pausing script: `

using UnityEngine; using
System.Collections;

public class PauseScript :
MonoBehaviour { public bool CanPause;
void Start() { CanPause = true; }
void OnGUI() { if (GUI.Button (new
Rect (Screen.width - (Screen.width /
60) - Screen.width / 20, Screen.height
/ 60, Screen.width / 20, Screen.width
/ 20), “Pause”)) { if (CanPause)
{
Time.timeScale = 0;
CanPause = false; } else {
Time.timeScale=1;
CanPause = true; } } } }

`

Of course, I need it in C#.

Thanks in advance.

If you’re lucky, OnGUI might be called first, before OnMouseDown. If so, you can simply create a global variable “clickedButton” and set it to true when the GUI.Button returns true. Then test it in your OnMouseDown for being false before jumping. And then reset it to false there. Now that’s a pretty nasty hack, and it probably doesn’t lend itself well to future expansion in your UI. But for a simple case where you only have a button or two but otherwise allow jumping with a click anywhere else, it would in theory work just fine (if OnGUI is called first before OnMouseDown).

Assuming you aren’t lucky, then an alternative is to create a quad, untextured, assign a collider to it, and move the OnMouseDown() method to a script on that quad. Now make that quad full screen and always in front of the camera. Since the quad is in the geometry, the UI will always receive input from the mouse at a higher priority. The downside is that you have a quad that gets in the way when you want to select stuff, so try to make it very small and very close to the camera (make the camera its parent).