First Commit
This commit is contained in:
commit
eed6b79efc
2836 files changed
+948481
No files matched your search
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerInputHandler : MonoBehaviour
|
||||
{
|
||||
[Header("Components")]
|
||||
[SerializeField] private PlayerMovement playerMovement;
|
||||
[SerializeField] private PlayerLook playerLook;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (playerMovement == null) playerMovement = GetComponent<PlayerMovement>();
|
||||
if (playerLook == null) playerLook = GetComponentInChildren<PlayerLook>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Пока открыто меню/планшет/окно торга — игрок стоит на месте (гравитация продолжает работать)
|
||||
if (GameInputLock.IsLocked)
|
||||
{
|
||||
if (playerMovement != null) playerMovement.ProcessMove(Vector2.zero);
|
||||
return;
|
||||
}
|
||||
|
||||
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.enabled)
|
||||
playerLook.ProcessLook(lookInput);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user