2026-09-19 16:56:59 +03:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class PlayerInteractor : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] private float interactRange = 3f;
|
|
|
|
|
[SerializeField] private LayerMask interactableLayer; // Создайте слой "Interactable" в Unity
|
|
|
|
|
|
2026-09-20 02:35:27 +03:00
|
|
|
[Header("References")]
|
|
|
|
|
[SerializeField] private UIManager uiManager;
|
|
|
|
|
|
2026-09-19 16:56:59 +03:00
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
// Пускаем луч из центра экрана
|
|
|
|
|
Ray ray = new Ray(transform.position, transform.forward);
|
|
|
|
|
|
2026-09-30 03:22:34 +03:00
|
|
|
if (Physics.Raycast(ray, out RaycastHit hit, interactRange, interactableLayer, QueryTriggerInteraction.Collide))
|
2026-09-19 16:56:59 +03:00
|
|
|
{
|
|
|
|
|
IInteractable interactable = hit.collider.GetComponentInParent<IInteractable>();
|
|
|
|
|
|
|
|
|
|
if (interactable != null)
|
|
|
|
|
{
|
2026-09-20 02:35:27 +03:00
|
|
|
uiManager.ShowPrompt(interactable.GetPrompt());
|
2026-09-19 16:56:59 +03:00
|
|
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.E))
|
|
|
|
|
{
|
|
|
|
|
interactable.Interact(transform.root.gameObject);
|
2026-09-20 02:35:27 +03:00
|
|
|
uiManager.HidePrompt();
|
2026-09-19 16:56:59 +03:00
|
|
|
}
|
2026-09-20 02:35:27 +03:00
|
|
|
|
|
|
|
|
return;
|
2026-09-19 16:56:59 +03:00
|
|
|
}
|
|
|
|
|
}
|
2026-09-20 02:35:27 +03:00
|
|
|
|
|
|
|
|
uiManager.HidePrompt();
|
2026-09-19 16:56:59 +03:00
|
|
|
}
|
|
|
|
|
}
|