Files
TopDown/Assets/Scripts/Interactable.cs

35 lines
1009 B
C#
Raw Normal View History

2026-08-04 16:56:27 +01:00
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);
}
}