53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
namespace OnlyScove.Scripts
|
|
{
|
|
public abstract class BaseInteractable : MonoBehaviour, IInteractable
|
|
{
|
|
[Header("Interaction Settings")]
|
|
[SerializeField] protected ObjectInteraction interactionData;
|
|
|
|
private float lastInteractTime;
|
|
|
|
public virtual string InteractionPrompt => interactionData != null ? interactionData.promptText : "Tương tác";
|
|
|
|
public virtual void OnInteract(GameObject interactor)
|
|
{
|
|
// Kiểm tra Cooldown
|
|
float cooldown = interactionData != null ? interactionData.interactionCooldown : 0.5f;
|
|
if (Time.time < lastInteractTime + cooldown)
|
|
return;
|
|
|
|
lastInteractTime = Time.time;
|
|
|
|
// Phát âm thanh nếu có
|
|
if (interactionData != null && interactionData.interactionSound != null)
|
|
{
|
|
AudioSource.PlayClipAtPoint(interactionData.interactionSound, transform.position);
|
|
}
|
|
|
|
// Tạo hiệu ứng VFX nếu có
|
|
if (interactionData != null && interactionData.interactionVFX != null)
|
|
{
|
|
Instantiate(interactionData.interactionVFX, transform.position, Quaternion.identity);
|
|
}
|
|
|
|
// Gọi logic tương tác cụ thể của từng loại vật thể
|
|
PerformInteraction(interactor);
|
|
}
|
|
|
|
public virtual void OnHoverEnter()
|
|
{
|
|
// Sẽ thêm logic Highlight ở Giai đoạn 4
|
|
}
|
|
|
|
public virtual void OnHoverExit()
|
|
{
|
|
// Sẽ xóa logic Highlight ở Giai đoạn 4
|
|
}
|
|
|
|
// Logic cụ thể bắt buộc các lớp con (Cửa, Cần gạt...) phải triển khai
|
|
protected abstract void PerformInteraction(GameObject interactor);
|
|
}
|
|
}
|