Добавляю машины и настраиваю их
This commit is contained in:
1 parent
1c106ea853
commit
a8238ab49e
363 files changed
+54820
-687
No files matched your search
@@ -0,0 +1,62 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user