test mesh
This commit is contained in:
@@ -16,10 +16,14 @@ public class PlayerInput : MonoBehaviour
|
||||
public InputActionAsset actions;
|
||||
|
||||
// ── Непрерывные значения ──────────────────────────────────────────────────
|
||||
public Vector2 MoveInput { get; private set; }
|
||||
public Vector2 LookInput { get; private set; }
|
||||
public bool Crouch { get; private set; }
|
||||
public bool Run { get; private set; }
|
||||
public Vector2 MoveInput { get; private set; }
|
||||
public Vector2 LookInput { get; private set; }
|
||||
public bool Crouch { get; private set; }
|
||||
public bool Run { get; private set; }
|
||||
/// <summary>ЛКМ удержана (разрушение блока). False когда инвентарь открыт.</summary>
|
||||
public bool BreakHeld { get; private set; }
|
||||
/// <summary>ПКМ нажата в этом кадре (постановка блока). False когда инвентарь открыт.</summary>
|
||||
public bool PlacePressed { get; private set; }
|
||||
|
||||
// ── Дискретные события ────────────────────────────────────────────────────
|
||||
public event Action OnToggleInventory;
|
||||
@@ -107,12 +111,17 @@ public class PlayerInput : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_gameplayMap == null || !_gameplayMap.enabled) return;
|
||||
bool gameplayActive = _gameplayMap != null && _gameplayMap.enabled;
|
||||
|
||||
MoveInput = _gameplayMap["Move"].ReadValue<Vector2>();
|
||||
LookInput = _gameplayMap["Look"].ReadValue<Vector2>();
|
||||
Crouch = _gameplayMap["Crouch"].IsPressed();
|
||||
Run = _gameplayMap["Run"].IsPressed();
|
||||
MoveInput = gameplayActive ? _gameplayMap["Move"].ReadValue<Vector2>() : Vector2.zero;
|
||||
LookInput = gameplayActive ? _gameplayMap["Look"].ReadValue<Vector2>() : Vector2.zero;
|
||||
Crouch = gameplayActive && _gameplayMap["Crouch"].IsPressed();
|
||||
Run = gameplayActive && _gameplayMap["Run"].IsPressed();
|
||||
|
||||
// Мышь через New Input System — отключаются вместе с gameplay
|
||||
var mouse = UnityEngine.InputSystem.Mouse.current;
|
||||
BreakHeld = gameplayActive && (mouse?.leftButton.isPressed ?? false);
|
||||
PlacePressed = gameplayActive && (mouse?.rightButton.wasPressedThisFrame ?? false);
|
||||
}
|
||||
|
||||
// ── Сохранение/загрузка биндингов ────────────────────────────────────────
|
||||
|
||||
@@ -60,9 +60,20 @@ public class charecter : MonoBehaviour
|
||||
}
|
||||
|
||||
PlayerInput.Instance.OnPickupPressed += TryPickupNearbyItem;
|
||||
PlayerInput.Instance.OnJumpPressed += () => { _jumpRequested = true; };
|
||||
PlayerInput.Instance.OnJumpPressed += OnJumpPressed;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (PlayerInput.Instance != null)
|
||||
{
|
||||
PlayerInput.Instance.OnPickupPressed -= TryPickupNearbyItem;
|
||||
PlayerInput.Instance.OnJumpPressed -= OnJumpPressed;
|
||||
}
|
||||
}
|
||||
|
||||
void OnJumpPressed() => _jumpRequested = true;
|
||||
|
||||
void Update()
|
||||
{
|
||||
HandleLook();
|
||||
@@ -85,14 +96,19 @@ public class charecter : MonoBehaviour
|
||||
|
||||
foreach (var col in colliders)
|
||||
{
|
||||
var worldItem = col.GetComponent<WorldItem>();
|
||||
// Ищем WorldItem на коллайдере ИЛИ на любом родителе —
|
||||
// чтобы дочерние меши (Visual, default и т.д.) тоже находили своего владельца
|
||||
var worldItem = col.GetComponentInParent<WorldItem>();
|
||||
if (worldItem == null) continue;
|
||||
|
||||
// Дедупликация: пропускаем если этот WorldItem уже учтён через другой коллайдер
|
||||
if (worldItem == closestItem) continue;
|
||||
|
||||
float dist = Vector3.Distance(transform.position, worldItem.transform.position);
|
||||
if (dist < closestDist && dist <= worldItem.interactRange)
|
||||
{
|
||||
closestDist = dist;
|
||||
closestItem = worldItem;
|
||||
closestDist = dist;
|
||||
closestItem = worldItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +159,7 @@ public class charecter : MonoBehaviour
|
||||
if (_jumpRequested && !isCrouching)
|
||||
{
|
||||
_verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||
_anim?.SetTrigger(HashJump);
|
||||
if (_anim != null) _anim.SetTrigger(HashJump);
|
||||
}
|
||||
_jumpRequested = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user