update hehehe
This commit is contained in:
@@ -1,47 +1,75 @@
|
||||
using OnlyScove.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class MyUIDisplay : MonoBehaviour
|
||||
public class MyUIDisplay : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
public PlayerDebugProvider playerDebugProvider;
|
||||
|
||||
[Header("UI Prompt")]
|
||||
public GameObject interactionPromptContainer;
|
||||
|
||||
public UnityEngine.UI.Text interactionPromptText;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
public PlayerDebugProvider playerDebugProvider;
|
||||
|
||||
[Header("UI Prompt")]
|
||||
public GameObject interactionPromptContainer;
|
||||
public TextMeshProUGUI interactionPromptText;
|
||||
//if (playerDebugProvider == null)
|
||||
//playerDebugProvider = FindFirstObjectByType<PlayerDebugProvider>();
|
||||
|
||||
private void Start()
|
||||
// Luôn ẩn lúc bắt đầu
|
||||
if (interactionPromptContainer != null)
|
||||
interactionPromptContainer.SetActive(false);
|
||||
|
||||
TryFindPlayer();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (playerDebugProvider == null)
|
||||
{
|
||||
if (playerDebugProvider == null)
|
||||
playerDebugProvider = FindFirstObjectByType<PlayerDebugProvider>();
|
||||
|
||||
// Luôn ẩn lúc bắt đầu
|
||||
if (interactionPromptContainer != null)
|
||||
interactionPromptContainer.SetActive(false);
|
||||
TryFindPlayer();
|
||||
if (playerDebugProvider == null) return;
|
||||
}
|
||||
if (interactionPromptContainer == null) return;
|
||||
|
||||
private void Update()
|
||||
IInteractable interactable = playerDebugProvider.GetActiveInteractable();
|
||||
|
||||
if (interactable != null)
|
||||
{
|
||||
if (playerDebugProvider == null || interactionPromptContainer == null) return;
|
||||
// Hiện UI tại vị trí cố định bạn đã đặt trong Canvas
|
||||
interactionPromptContainer.SetActive(true);
|
||||
|
||||
IInteractable interactable = playerDebugProvider.GetActiveInteractable();
|
||||
|
||||
if (interactable != null)
|
||||
if (!interactionPromptContainer.activeSelf)
|
||||
{
|
||||
// Hiện UI tại vị trí cố định bạn đã đặt trong Canvas
|
||||
interactionPromptContainer.SetActive(true);
|
||||
}
|
||||
|
||||
if (interactionPromptText != null)
|
||||
{
|
||||
interactionPromptText.text = interactable.InteractionPrompt;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user