Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.InputSystem;
- public class PauseHandler : MonoBehaviour
- {
- PlayerInput _playerInput;
- private bool _isPausing;
- public bool IsPaused;
- public GameObject pauseMenu;
- void Awake()
- {
- _playerInput = new PlayerInput();
- _playerInput.MenuControls.Pause.started += onPause;
- _playerInput.MenuControls.Pause.canceled += onPause;
- _playerInput.MenuControls.Pause.performed += onPause;
- }
- private void Start()
- {
- pauseMenu.SetActive(false);
- }
- void onPause(InputAction.CallbackContext context)
- {
- _isPausing = context.ReadValueAsButton();
- Debug.Log("attempting to pause");
- }
- public void HandlePause()
- {
- if (_isPausing && Time.timeScale > 0)
- {
- Debug.Log("paused");
- Time.timeScale = 0;
- AudioListener.pause = true;
- IsPaused = true;
- pauseMenu.SetActive(true);
- }
- else if (!_isPausing && Time.timeScale == 0)
- {
- Debug.Log("unpaused");
- Time.timeScale = 1;
- AudioListener.pause = false;
- IsPaused = false;
- pauseMenu.SetActive(false);
- }
- }
- private void Update()
- {
- HandlePause();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement