Hi , I am creating a game where Player is running and jumping on mouse click. So I made Pause button for the game , but issue that I have now is that when Pause button is being pressed Player jumps and then game stops. How do I make my Pause button not interact with Player jumping ? I’m not that good with programming so this issue is hard to resolve by myself . Thanks for your time!
Player controls :
// Update is called once per frame
void Update () {
grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
if (transform.position.x > speedMilestoneCount)
{
speedMilestoneCount += speedIncreaseMilestone;
speedIncreaseMilestone = speedIncreaseMilestone * speedMultiplier;
moveSpeed = moveSpeed * speedMultiplier;
}
myRigidbody.velocity = new Vector2 (moveSpeed, myRigidbody.velocity.y); //Controlls
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0)) {
if (grounded) {
myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce);
}
}
if (Input.GetKey (KeyCode.Space) || Input.GetMouseButton (0))
{
if (jumpTimeCounter > 0)
{
myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce);
jumpTimeCounter -= Time.deltaTime;
}
}
if(Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
{
jumpTimeCounter = 0;
}
if(grounded)
{
jumpTimeCounter = jumpTime;
}
myAnimator.SetFloat ("Speed", myRigidbody.velocity.x);
myAnimator.SetBool ("Grounded", grounded);
}
Pause script :
public void PauseGame ()
{
Time.timeScale = 0f;
pauseMenu.SetActive (true);
}