我正在尝试新的Unity Input System,到目前为止效果很好。但是,我遇到了一个小障碍。我想实施一个“暂停”系统。游戏暂停时,应禁用玩家控件。当游戏重新开始时,玩家的控件应恢复到正常工作状态。这一半有效。在暂停游戏后,我成功禁用了播放器控件,但在恢复游戏后,控件仍然不起作用。
班上负责运动的部分:
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();
}
同一个类中的暂停功能:
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;
}
}
我做错什么了吗?如何实现所需的行为?