Implement movement input handling and update UI components for treasure collection
This commit is contained in:
@@ -7,6 +7,7 @@ public class InputManager : MonoBehaviour
|
||||
private InputActions _actions;
|
||||
|
||||
public Vector2 Movement { get; private set; }
|
||||
public event Action<Vector2> OnMovementChanged;
|
||||
public event Action OnFire;
|
||||
|
||||
private void Awake()
|
||||
@@ -14,6 +15,7 @@ public class InputManager : MonoBehaviour
|
||||
_actions = new InputActions();
|
||||
|
||||
// Movement
|
||||
_actions.Player.Movement.started += OnMovementPerformed;
|
||||
_actions.Player.Movement.performed += OnMovementPerformed;
|
||||
_actions.Player.Movement.canceled += OnMovementCanceled;
|
||||
|
||||
@@ -31,16 +33,21 @@ public class InputManager : MonoBehaviour
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
_actions.Disable();
|
||||
if (_actions != null)
|
||||
{
|
||||
_actions.Disable();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMovementPerformed(InputAction.CallbackContext ctx)
|
||||
{
|
||||
Movement = ctx.ReadValue<Vector2>();
|
||||
OnMovementChanged?.Invoke(Movement);
|
||||
}
|
||||
|
||||
private void OnMovementCanceled(InputAction.CallbackContext ctx)
|
||||
{
|
||||
Movement = Vector2.zero;
|
||||
OnMovementChanged?.Invoke(Movement);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user