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

76 lines
2.0 KiB
C#
Raw Normal View History

2026-03-26 20:27:19 +07:00
using OnlyScove.Scripts;
using UnityEngine;
2026-04-15 10:45:47 +07:00
using UnityEngine.UI;
2026-03-26 20:27:19 +07:00
using TMPro;
namespace UI
{
2026-04-15 10:45:47 +07:00
public class MyUIDisplay : MonoBehaviour
{
[Header("References")]
public PlayerDebugProvider playerDebugProvider;
[Header("UI Prompt")]
public GameObject interactionPromptContainer;
public UnityEngine.UI.Text interactionPromptText;
private void Start()
2026-03-26 20:27:19 +07:00
{
2026-04-15 10:45:47 +07:00
//if (playerDebugProvider == null)
//playerDebugProvider = FindFirstObjectByType<PlayerDebugProvider>();
2026-03-26 20:27:19 +07:00
2026-04-15 10:45:47 +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-15 10:45:47 +07:00
TryFindPlayer();
}
private void Update()
{
if (playerDebugProvider == null)
{
TryFindPlayer();
if (playerDebugProvider == null) return;
2026-04-01 02:41:07 +07:00
}
2026-04-15 10:45:47 +07:00
if (interactionPromptContainer == null) return;
2026-03-26 20:27:19 +07:00
2026-04-15 10:45:47 +07:00
IInteractable interactable = playerDebugProvider.GetActiveInteractable();
if (interactable != null)
2026-04-01 02:41:07 +07:00
{
2026-04-15 10:45:47 +07:00
// 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-15 10:45:47 +07:00
if (!interactionPromptContainer.activeSelf)
2026-04-01 02:41:07 +07:00
{
interactionPromptContainer.SetActive(true);
}
2026-04-15 10:45:47 +07:00
if (interactionPromptText != null)
interactionPromptText.text = interactable.InteractionPrompt;
}
else
{
if (interactionPromptContainer.activeSelf)
2026-04-01 02:41:07 +07:00
interactionPromptContainer.SetActive(false);
2026-03-26 20:27:19 +07:00
}
}
2026-04-15 10:45:47 +07:00
private void TryFindPlayer()
{
if (PlayerStateMachine.Local != null)
{
playerDebugProvider = PlayerStateMachine.Local.GetComponent<PlayerDebugProvider>();
}
if (playerDebugProvider == null)
{
playerDebugProvider = Object.FindFirstObjectByType<PlayerDebugProvider>();
}
}
}
}