- Home /
hard to explain but, when my game is paused my space bar goes weird.
so basically when my game is paused I can click resume or press ESC to unpause however if I click to resume, the next time I pause, pressing space will cause the game to unpause and my character to jump, this does not happen if I resume by pressing ESC. Idk if you can help but best of luck and many thanks.
here is my pause menu manager: using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine;
public class PauseMenuManager : MonoBehaviour { public static bool GamePaused = false;
public GameObject pauseMenuUI;
public GameObject gameOver;
public GameObject playerMovement;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (gameOver.activeSelf)
{
}
else
{
if (GamePaused)
{
Resume();
}
else
{
Pause();
}
}
}
}
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GamePaused = false;
PlayerMovement movement = playerMovement.GetComponent<PlayerMovement>();
movement.enabled = true;
}
public void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GamePaused = true;
PlayerMovement movement = playerMovement.GetComponent<PlayerMovement>();
movement.enabled = false;
}
}
here is my player movement:
using UnityEngine;
public class PlayerMovement : MonoBehaviour { public CharacterController2D controller; public Animator animator; public DeathDetector deathdetector;
public float runSpeeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeeed;
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
}
else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
}
public void OnDeath()
{
animator.SetBool("IsDead", true);
}
public void OnLanding()
{
animator.SetBool("IsJumping", false);
}
public void OnCrouching(bool isCrouching)
{
animator.SetBool("IsCrouching", isCrouching);
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
if my description is bugged and some code is appearing as text I'm sorry.