Сделал базовое управление машиной и персонажем
This commit is contained in:
1 parent
10d42b72b8
commit
48753f65fb
152 files changed
+15117
-174
No files matched your search
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerInteractor : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float interactRange = 3f;
|
||||
[SerializeField] private LayerMask interactableLayer; // Создайте слой "Interactable" в Unity
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Пускаем луч из центра экрана
|
||||
Ray ray = new Ray(transform.position, transform.forward);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, interactRange, interactableLayer))
|
||||
{
|
||||
IInteractable interactable = hit.collider.GetComponentInParent<IInteractable>();
|
||||
|
||||
if (interactable != null)
|
||||
{
|
||||
// Здесь в будущем можно выводить UI текст interactable.GetPrompt() на экран
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.E))
|
||||
{
|
||||
// Передаем корневой объект игрока (не камеру)
|
||||
Debug.Log("Кнопка нажата");
|
||||
interactable.Interact(transform.root.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user