I am new in unity, and I faced a confusing problem when I wanted to pause my game by pressing key once using input system, but is seems like to pause the game, I have to keep pressing the whitespace. In input system, I set the setting of pressing whitespace as “press and release” bind to pause action which is set as a button action type and “press only”. Can anyone help me? Thank you in advance
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PauseManager : MonoBehaviour
{
public float timeLeft = 0;
public bool timeOn = false;
public Text timeText;
public static bool pause = false;
public PauseActionInput _pauseAction;
public AudioSource audiosource1;
public GameObject pausemenu;
public void Start()
{
_pauseAction.PauseActionMap.pause.performed += _ => determine_pause();
}
public void Awake()
{
_pauseAction = new PauseActionInput();
}
public void Update()
{
if (PauseManager.pause) return;
}
private void OnEnable()
{
_pauseAction.Enable();
}
private void OnDisable()
{
_pauseAction.Disable();
}
public void determine_pause()
{
if (pause)
{
resumeGame();
}
else
{
pauseGame();
}
}
public void resumeGame()
{
Time.timeScale = 1;
AudioListener.pause = false;
pausemenu.SetActive(false);
pause = false;
Debug.Log("game is resume");
}
public void pauseGame()
{
Time.timeScale = 0;
AudioListener.pause = true;
pausemenu.SetActive(true);
pause = true;
Debug.Log("game is stopped");
}
}