Perekyp/Assets/Scripts/Player/Movement/PlayerInputHandler.cs

39 lines
1.2 KiB
C#

using UnityEngine;
public class PlayerInputHandler : MonoBehaviour
{
[Header("Components")]
[SerializeField] private PlayerMovement playerMovement;
[SerializeField] private PlayerLook playerLook;
private void Update()
{
HandleMovementInput();
HandleLookInput();
}
private void HandleMovementInput()
{
// Читаем оси WASD. GetAxisRaw дает более резкое, отзывчивое управление без инерции.
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
// Нормализуем вектор, чтобы игрок не двигался быстрее по диагонали
Vector2 moveInput = new Vector2(horizontal, vertical).normalized;
if (playerMovement != null)
playerMovement.ProcessMove(moveInput);
}
private void HandleLookInput()
{
// Читаем движение мыши
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
Vector2 lookInput = new Vector2(mouseX, mouseY);
if (playerLook != null)
playerLook.ProcessLook(lookInput);
}
}