Files
daluandou/Assets/Scripts/UI脚本/GoldUI.cs
T
huadexuan 48395ab414 ```
feat(gameplay): 实现护盾系统和强化增益选择机制

- 新增护盾功能,包括护盾数值显示和护盾条UI
- 重构盾卫技能,实现坚固壁垒技能效果
- 添加暴击率、吸血率等战斗属性
- 优化增益选择界面,新增传奇品质和刷新机制
- 调整材质纹理和文字着色器效果
- 修复金币显示格式问题
```
2026-10-09 18:13:18 +08:00

58 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
/// <summary>
/// 金币 UI 显示,显示在屏幕右上角
/// </summary>
[RequireComponent(typeof(Text))]
public class GoldUI : MonoBehaviour
{
private Text goldText;
private bool isSubscribed = false;
private void Awake()
{
goldText = GetComponent<Text>();
}
private void Start()
{
// 延迟订阅,确保 GoldManager 已初始化
StartCoroutine(SubscribeToGoldManager());
}
private IEnumerator SubscribeToGoldManager()
{
// 等待 GoldManager 初始化
while (GoldManager.Instance == null)
{
yield return null;
}
// 订阅事件
GoldManager.Instance.OnGoldChanged += UpdateGoldDisplay;
isSubscribed = true;
// 立即更新显示
UpdateGoldDisplay(GoldManager.Instance.CurrentGold);
}
private void OnDestroy()
{
// 取消订阅
if (isSubscribed && GoldManager.Instance != null)
{
GoldManager.Instance.OnGoldChanged -= UpdateGoldDisplay;
}
}
private void UpdateGoldDisplay(int newGold)
{
if (goldText != null)
{
goldText.text = newGold.ToString();
}
}
}