37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace OnlyScove.Scripts
|
|
{
|
|
public abstract class BaseInteractable : MonoBehaviour, IInteractable
|
|
{
|
|
[SerializeField] protected ObjectInteraction interactionData;
|
|
|
|
private float lastInteractTime;
|
|
|
|
public virtual string InteractionPrompt => interactionData != null ? interactionData.promptText : "Interact";
|
|
|
|
public virtual void OnInteract(PlayerStateMachine player)
|
|
{
|
|
if (Time.time < lastInteractTime + (interactionData != null ? interactionData.interactionCooldown : 0f))
|
|
return;
|
|
|
|
lastInteractTime = Time.time;
|
|
|
|
// Play sound if assigned
|
|
if (interactionData != null && interactionData.interactionSound != null)
|
|
{
|
|
AudioSource.PlayClipAtPoint(interactionData.interactionSound, transform.position);
|
|
}
|
|
|
|
// Spawn VFX if assigned
|
|
if (interactionData != null && interactionData.interactionVFX != null)
|
|
{
|
|
Instantiate(interactionData.interactionVFX, transform.position, Quaternion.identity);
|
|
}
|
|
|
|
PerformInteraction(player);
|
|
}
|
|
|
|
protected abstract void PerformInteraction(PlayerStateMachine player);
|
|
}
|
|
} |