update hehehe

This commit is contained in:
2026-04-15 10:45:47 +07:00
parent e51f5cb82d
commit 02c2390d83
5 changed files with 137 additions and 37 deletions

View File

@@ -19,6 +19,16 @@ namespace OnlyScove.Scripts
private Material lampMaterial;
private Color originalEmissionColor;
public override string InteractionPrompt
{
get
{
string action = isOn ? "Tắt " : "Bật ";
string name = interactionData != null ? interactionData.promptText : "Đèn";
return action + name;
}
}
private void Start()
{
// Khởi tạo Material (tạo bản thực thi riêng để không lỗi Shader)

View File

@@ -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>();
}
}
}
}