update
This commit is contained in:
@@ -4,34 +4,49 @@ 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 : "Interact";
|
||||
public virtual string InteractionPrompt => interactionData != null ? interactionData.promptText : "Tương tác";
|
||||
|
||||
// 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user