Добавил скрипты для более реалистичной физики, но они шляпа полная.
This commit is contained in:
1 parent
f9eb14868d
commit
5f25a8eab4
32 files changed
+490
-1643
No files matched your search
@@ -2,45 +2,80 @@ using UnityEngine;
|
||||
|
||||
public class PlayerInteractor : MonoBehaviour
|
||||
{
|
||||
[Header("Настройки луча")]
|
||||
[SerializeField] private float interactRange = 3f;
|
||||
[SerializeField] private LayerMask interactableLayer; // Создайте слой "Interactable" в Unity
|
||||
[SerializeField] private KeyCode primaryKey = KeyCode.E;
|
||||
[SerializeField] private KeyCode secondaryKey = KeyCode.R;
|
||||
|
||||
[Header("References")]
|
||||
[SerializeField] private LayerMask interactableLayer;
|
||||
|
||||
[Header("Клавиши управления")]
|
||||
[SerializeField] private KeyCode primaryKey = KeyCode.E; // Работа с деталью (открыть/взять)
|
||||
[SerializeField] private KeyCode secondaryKey = KeyCode.R; // Снять деталь
|
||||
[SerializeField] private KeyCode enterVehicleKey = KeyCode.F; // Сесть в машину
|
||||
|
||||
[Header("Ссылки")]
|
||||
[SerializeField] private UIManager uiManager;
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (uiManager != null) uiManager.HidePrompt();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Пускаем луч из центра экрана
|
||||
Ray ray = new Ray(transform.position, transform.forward);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, interactRange, interactableLayer, QueryTriggerInteraction.Collide))
|
||||
{
|
||||
// Ищем интерактивную деталь (дверь, капот, крыло)
|
||||
IInteractable interactable = hit.collider.GetComponentInParent<IInteractable>();
|
||||
|
||||
if (interactable != null)
|
||||
// Ищем скрипт автомобиля в родительских объектах
|
||||
VehicleInteraction vehicle = hit.collider.GetComponentInParent<VehicleInteraction>();
|
||||
|
||||
if (interactable != null || vehicle != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(interactable.GetPrompt()) && uiManager!=null)
|
||||
// Формируем комбинированную подсказку
|
||||
string prompt = "";
|
||||
|
||||
if (vehicle != null && !vehicle.isPlayerInside)
|
||||
{
|
||||
uiManager.ShowPrompt(interactable.GetPrompt());
|
||||
prompt += "[F] Сесть в авто ";
|
||||
}
|
||||
else if (uiManager != null)
|
||||
|
||||
if (interactable != null)
|
||||
{
|
||||
uiManager.HidePrompt();
|
||||
string partPrompt = interactable.GetPrompt();
|
||||
if (!string.IsNullOrEmpty(partPrompt))
|
||||
{
|
||||
prompt += partPrompt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Input.GetKeyDown(primaryKey))
|
||||
|
||||
if (!string.IsNullOrEmpty(prompt) && uiManager != null)
|
||||
{
|
||||
uiManager.ShowPrompt(prompt);
|
||||
}
|
||||
|
||||
// 1. Посадка в авто на F
|
||||
if (Input.GetKeyDown(enterVehicleKey) && vehicle != null)
|
||||
{
|
||||
vehicle.Interact(transform.root.gameObject);
|
||||
if (uiManager != null) uiManager.HidePrompt();
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Основное действие с деталью на E (Открыть/Закрыть)
|
||||
if (Input.GetKeyDown(primaryKey) && interactable != null)
|
||||
{
|
||||
interactable.Interact(transform.root.gameObject);
|
||||
}
|
||||
|
||||
// 3. Вторичное действие с деталью на R (Снять в руки)
|
||||
if (Input.GetKeyDown(secondaryKey))
|
||||
{
|
||||
ISecondaryInteractable secondary = hit.collider.GetComponentInParent<ISecondaryInteractable>();
|
||||
secondary?.SecondaryInteract(transform.root.gameObject);
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -50,12 +85,4 @@ public class PlayerInteractor : MonoBehaviour
|
||||
uiManager.HidePrompt();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (uiManager != null)
|
||||
{
|
||||
uiManager.HidePrompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user