Implement movement input handling and update UI components for treasure collection

This commit is contained in:
2026-06-20 19:11:24 +03:00
parent ad6388f330
commit a510443130
9 changed files with 247 additions and 26 deletions
+8 -1
View File
@@ -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);
}
}