62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using UnityEngine;
|
||
|
||
public class PlayerHands : MonoBehaviour
|
||
{
|
||
[Header("Точка удержания")]
|
||
[Tooltip("Пустой дочерний объект перед камерой игрока")]
|
||
[SerializeField] private Transform holdPoint;
|
||
|
||
[Header("Клавиши управления")]
|
||
[SerializeField] private KeyCode dropKey = KeyCode.G;
|
||
[SerializeField] private KeyCode throwKey = KeyCode.Mouse1; // Правая кнопка мыши
|
||
[SerializeField] private float throwForce = 7f;
|
||
|
||
private CarPart currentPart;
|
||
|
||
public bool IsHolding => currentPart != null;
|
||
public CarPart CurrentPart => currentPart;
|
||
public Transform HoldPoint => holdPoint;
|
||
|
||
private void Update()
|
||
{
|
||
if (!IsHolding) return;
|
||
|
||
// Бросить под ноги
|
||
if (Input.GetKeyDown(dropKey))
|
||
{
|
||
DropCurrentPart(Vector3.zero);
|
||
}
|
||
// Бросить вперед с силой
|
||
else if (Input.GetKeyDown(throwKey))
|
||
{
|
||
Vector3 force = holdPoint.forward * throwForce;
|
||
DropCurrentPart(force);
|
||
}
|
||
}
|
||
|
||
public void PickUp(CarPart part)
|
||
{
|
||
if (IsHolding)
|
||
{
|
||
// Если уже что-то держим — роняем старую деталь под ноги
|
||
DropCurrentPart(Vector3.zero);
|
||
}
|
||
|
||
currentPart = part;
|
||
currentPart.OnPickedUp(holdPoint);
|
||
}
|
||
|
||
public void DropCurrentPart(Vector3 impulse)
|
||
{
|
||
if (!IsHolding) return;
|
||
|
||
CarPart dropped = currentPart;
|
||
currentPart = null; // Освобождаем руки
|
||
dropped.OnDropped(impulse);
|
||
}
|
||
|
||
public void ClearHandAfterInstall()
|
||
{
|
||
currentPart = null;
|
||
}
|
||
} |