Files
2026-06-06 11:43:11 +03:00

47 lines
976 B
C#

using System;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
private InputActions _actions;
public Vector2 Movement { get; private set; }
public event Action OnFire;
private void Awake()
{
_actions = new InputActions();
// Movement
_actions.Player.Movement.performed += OnMovementPerformed;
_actions.Player.Movement.canceled += OnMovementCanceled;
// Fire
_actions.Player.Fire.performed += ctx => OnFire?.Invoke();
}
public void OnEnable()
{
if (_actions != null)
{
_actions.Enable();
}
}
public void OnDisable()
{
_actions.Disable();
}
private void OnMovementPerformed(InputAction.CallbackContext ctx)
{
Movement = ctx.ReadValue<Vector2>();
}
private void OnMovementCanceled(InputAction.CallbackContext ctx)
{
Movement = Vector2.zero;
}
}