first commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class InteractableObject : MonoBehaviour
|
||||
{
|
||||
public Transform player;
|
||||
public float interactionRadius = 2.4f;
|
||||
public string promptText = "Нажмите E, чтобы осмотреть статую";
|
||||
public float promptDuration = 1.2f;
|
||||
public bool interactOnce = true;
|
||||
public UnityEvent onInteract = new UnityEvent();
|
||||
|
||||
private bool hasInteracted;
|
||||
private float nextPromptTime;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
GameObject playerObject = GameObject.FindGameObjectWithTag("Player");
|
||||
player = playerObject != null ? playerObject.transform : null;
|
||||
}
|
||||
|
||||
if (player == null || (interactOnce && hasInteracted))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isNear = Vector3.Distance(transform.position, player.position) <= interactionRadius;
|
||||
|
||||
if (!isNear)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time >= nextPromptTime)
|
||||
{
|
||||
// Repeated short prompts keep the interaction readable while the player stays nearby.
|
||||
HintManager.Instance?.ShowHint(promptText, promptDuration);
|
||||
nextPromptTime = Time.time + promptDuration + 0.25f;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.E))
|
||||
{
|
||||
hasInteracted = true;
|
||||
onInteract?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user