76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
using OnlyScove.Scripts;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
namespace UI
|
|
{
|
|
public class MyUIDisplay : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
public PlayerDebugProvider playerDebugProvider;
|
|
|
|
[Header("UI Prompt")]
|
|
public GameObject interactionPromptContainer;
|
|
|
|
public UnityEngine.UI.Text interactionPromptText;
|
|
|
|
private void Start()
|
|
{
|
|
//if (playerDebugProvider == null)
|
|
//playerDebugProvider = FindFirstObjectByType<PlayerDebugProvider>();
|
|
|
|
// Luôn ẩn lúc bắt đầu
|
|
if (interactionPromptContainer != null)
|
|
interactionPromptContainer.SetActive(false);
|
|
|
|
TryFindPlayer();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (playerDebugProvider == null)
|
|
{
|
|
TryFindPlayer();
|
|
if (playerDebugProvider == null) return;
|
|
}
|
|
if (interactionPromptContainer == null) return;
|
|
|
|
IInteractable interactable = playerDebugProvider.GetActiveInteractable();
|
|
|
|
if (interactable != null)
|
|
{
|
|
// Hiện UI tại vị trí cố định bạn đã đặt trong Canvas
|
|
interactionPromptContainer.SetActive(true);
|
|
|
|
if (!interactionPromptContainer.activeSelf)
|
|
{
|
|
interactionPromptContainer.SetActive(true);
|
|
}
|
|
|
|
if (interactionPromptText != null)
|
|
interactionPromptText.text = interactable.InteractionPrompt;
|
|
}
|
|
else
|
|
{
|
|
if (interactionPromptContainer.activeSelf)
|
|
interactionPromptContainer.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void TryFindPlayer()
|
|
{
|
|
if (PlayerStateMachine.Local != null)
|
|
{
|
|
playerDebugProvider = PlayerStateMachine.Local.GetComponent<PlayerDebugProvider>();
|
|
}
|
|
|
|
if (playerDebugProvider == null)
|
|
{
|
|
playerDebugProvider = Object.FindFirstObjectByType<PlayerDebugProvider>();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|