Files
daluandou/Assets/Scripts/UI脚本/GoldUI.cs
T
huadexuan 336ec9980d ```
feat(gameplay): 更新防御关卡金币系统

- 修改金币显示文本格式,移除冒号分隔符
- 实现差异化金币奖励机制:小怪固定1金币,英雄/Boss单位固定5金币
- 添加战术倍率支持,确保最低1金币奖励
- 增加击杀日志输出功能
- 实现英雄/Boss单位识别逻辑,通过名称和角色数据进行判断
```
2026-10-09 00:00:46 +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}";
}
}
}