I'm trying the new Unity Input System and so far it's working great. However, I ran into a small snag. I want to implement a 'pause' system. When the game is paused, the player controls should be disabled. And when the game is resumed the player controls should be back in working order. This half works. I successfully disable the player controls when the game is paused, yet when the game is resumed the controls still don't work.
Part of the class responsible for movement:
public class ShapeMover : MonoBehaviour
{
public InputManager controls;
private float _lastFallTime;
private float _fallSpeed;
private ShapeSpawner _spawn;
private GameObject _shapeToMove;
private Transform _shapeToMoveTransform;
private bool _isGameOver;
private const float _leftRotationAngle = (float) -1.57079633;
private const float _rightRotationAngle = (float) 1.57079633;
private void Awake()
{
_spawn = FindObjectOfType<ShapeSpawner>();
_lastFallTime = 0f;
_fallSpeed = GameGrid.Instance.GetFallSpeed();
_isGameOver = false;
controls.Player.Movement.performed += ctx => Movement(ctx.ReadValue<Vector2>());
controls.Player.Drop.performed += ctx => Drop();
controls.Menu.Reset.performed += ctx => Restart();
controls.Menu.Pause.performed += ctx => PauseToggle();
SetShapeToMove();
}
Pause function in the same class:
private void PauseToggle()
{
var currentPauseState = GameGrid.Instance.IsPaused;
//If not paused, will pause
if (!currentPauseState)
{
controls.Player.Disable();
GameGrid.Instance.IsPaused = true;
}
else
{
controls.Player.Enable();
GameGrid.Instance.IsPaused = false;
}
}
Am I doing something wrong? How can I achieve the desired behavior?
IsPaused
to false? - SharpNip