Hi guys, I’m trying to set a pause menu with the new input system. I managed to set the input and functions, but the input is taken 2-3 times in the frame when I press the key/button. I don’t know why this happen, can anyone give me a hand please?
This is the code in the GameManager script:
public bool needPause;
public bool pressingPause;
public static bool isPaused = false;
private void Update()
{
//Handle Play/Pause
PausingGame();
}
// Play/Pause methods
void PausingGame()
{
if (needPause && pressingPause)
{
if (isPaused)
{
ResumeGame();
}
else
{
PauseGame();
}
}
}
public void PauseGame()
{
audioPlayer.PlayOpenPauseClip();
audioPlayer.GetComponent<AudioSource>().volume = 0.1f;
pausePanel.SetActive(true);
scoreText.text = "You Scored :\n" + scoreKeeper.GetScore();
InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsInDynamicUpdate;
Time.timeScale = 0f;
isPaused = true;
}
public void ResumeGame()
{
audioPlayer.GetComponent<AudioSource>().volume = 0.3f;
audioPlayer.PlayClosePauseClip();
pausePanel.SetActive(false);
InputSystem.settings.updateMode = InputSettings.UpdateMode.ProcessEventsInFixedUpdate;
Time.timeScale = 1f;
isPaused = false;
}
This is the code in the PlayerController script:
[HideInInspector] public bool pauseButtonPressed;
GameManager gameManager;
void Awake()
{
gameManager = FindObjectOfType<GameManager>();
}
private void OnPauseGame(InputValue value)
{
if(gameManager != null)
{
Debug.Log("Pause");
gameManager.pressingPause = value.isPressed;
}
}
Thanks in advance and if you need more code or other elements just ask.