c# one click and pauses the game and makes player jump

my player jumps on every click that happens . i’ve got a pause button(gui button) . my problem is that when i click the pause button , my player jumps once , and then the game pauses .

for player movement i’ve got this: if ((Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0)) && isPaused == false) { //jump }

and for pausing the game i’ve got this: if (GUI.Button (new Rect (10, 10, 100, 100), icon, myStyle)) { Time.timeScale = 0; playerMovement.Instance.isPaused = true; }

any ideas ?

Just making sure you’re checking for the pause button click before the player movement. Otherwise it would jump first, and then pause, like what’s happening.

The issue relies on TIME, it detects the jump (action input) first, and later detects the pause (pause input) on the UI element (pause button)… I fix this by checking a boolean variable before triggering the jump (action input) and on the pause script, delaying by a fraction of a second when this variable is re enabled… this is how it works for me:

Action Script:

public class PlayerController : MonoBehaviour {
static public bool pauseCheck=true;

	void Update()
	{
			
		if(Input.GetMouseButtonDown(0) pauseCheck ==true)
		{
			jump = true;
		}
	}
}

and Pause Script:

public class Pause : MonoBehaviour {

	static public bool paused = false;
	

	void OnMouseDown() {

		paused = !paused;
		PlayerController .pauseCheck =false ;

		if(paused){
			Time.timeScale = 0;
		}
		else{
			Time.timeScale = 1;
			StartCoroutine (pause());
		}


	}

	IEnumerator pause()
	{
		yield return new WaitForSeconds(0.1f);
		PlayerController .pauseCheck =true;
	}
}

Hope this help.

they are on different scripts . on different gameobjects . how to do that ?

EDIT: i’ve placed them on the same script , but the button is on void onGUI and movement is void update , it still jumps once before it pause the game