Files
BABA_YAGA/Assets/Scripts/UI/MyUIDisplay.cs

47 lines
1.4 KiB
C#
Raw Normal View History

2026-03-26 20:27:19 +07:00
using OnlyScove.Scripts;
using UnityEngine;
using TMPro;
namespace UI
{
public class MyUIDisplay : MonoBehaviour
{
public PlayerDebugProvider playerDebugProvider;
2026-04-01 02:41:07 +07:00
[Header("UI Prompt")]
public GameObject interactionPromptContainer;
public TextMeshProUGUI interactionPromptText;
2026-03-26 20:27:19 +07:00
2026-04-01 02:41:07 +07:00
private void Start()
2026-03-26 20:27:19 +07:00
{
2026-04-01 02:41:07 +07:00
if (playerDebugProvider == null)
playerDebugProvider = FindFirstObjectByType<PlayerDebugProvider>();
2026-03-26 20:27:19 +07:00
2026-04-01 02:41:07 +07:00
// Luôn ẩn lúc bắt đầu
if (interactionPromptContainer != null)
interactionPromptContainer.SetActive(false);
}
2026-03-26 20:27:19 +07:00
2026-04-01 02:41:07 +07:00
private void Update()
{
if (playerDebugProvider == null || interactionPromptContainer == null) return;
2026-03-26 20:27:19 +07:00
2026-04-01 02:41:07 +07:00
IInteractable interactable = playerDebugProvider.GetActiveInteractable();
if (interactable != null)
{
// Hiện UI tại vị trí cố định bạn đã đặt trong Canvas
interactionPromptContainer.SetActive(true);
2026-03-26 20:27:19 +07:00
2026-04-01 02:41:07 +07:00
if (interactionPromptText != null)
{
interactionPromptText.text = interactable.InteractionPrompt;
}
}
else
{
interactionPromptContainer.SetActive(false);
}
2026-03-26 20:27:19 +07:00
}
}
}