35 lines
1009 B
C#
35 lines
1009 B
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public interface IInteractable
|
|
{
|
|
void Interact(GameObject interactor);
|
|
string GetInteractionPrompt();
|
|
float GetInteractionRadius();
|
|
Transform GetTransform();
|
|
}
|
|
|
|
public class Interactable : MonoBehaviour, IInteractable
|
|
{
|
|
[Header("Interaction Settings")]
|
|
[SerializeField] private string prompt = "Interact";
|
|
[SerializeField] private float interactionRadius = 2.0f;
|
|
[SerializeField] private UnityEvent<GameObject> onInteract;
|
|
|
|
public virtual void Interact(GameObject interactor)
|
|
{
|
|
Debug.Log($"[Interactable] Interacted with {gameObject.name}");
|
|
onInteract?.Invoke(interactor);
|
|
}
|
|
|
|
public string GetInteractionPrompt() => prompt;
|
|
public float GetInteractionRadius() => interactionRadius;
|
|
public Transform GetTransform() => transform;
|
|
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
Gizmos.color = Color.yellow;
|
|
Gizmos.DrawWireSphere(transform.position, interactionRadius);
|
|
}
|
|
}
|