feat(buildings): 添加金矿建筑功能并优化建筑健康系统

- 为兵营和金矿添加伤害数字显示功能,包括持续时间、上升高度等参数
- 将金矿脚本重构为GoldMine组件,实现定时产出金币机制
- 为所有单位添加NavMeshAgent组件以支持导航寻路
- 为弓箭手、法师等单位添加分离半径和目标扩散参数
- 为建筑添加碰撞体和标签设置
- 修复当前能量字段命名规范(currentEnergy -> _currentEnergy)
- 调整金矿健康值从100提升至500
- 统一伤害数字显示相关属性配置
```
This commit is contained in:
huadexuan committed 2026-09-15 21:13:44 +08:00
1 parent 27df2aa8b1
commit 1cdb7c3910
22 files changed
+804 -55

No files matched your search

+59 -17
View File
@@ -1,36 +1,78 @@
using UnityEngine;
/// <summary>
/// 金矿建筑,定时产出金币
/// </summary>
public class GoldMine : MonoBehaviour
{
[Header("产出配置")]
[Min(0)] public int goldPerTick = 5;
[Min(0.1f)] public float productionInterval = 3f;
[Header("金币产出")]
[Tooltip("每次产出的金币数量")]
[SerializeField] private int goldPerProduction = 50;
private float timer;
private BuildingHealth buildingHealth;
[Tooltip("产出间隔(秒)")]
[SerializeField] private float productionInterval = 5f;
[Header("可选:血条和进度条")]
[SerializeField] private WorldHealthBar healthBar;
private float productionTimer = 0f;
private void Awake()
{
buildingHealth = GetComponent<BuildingHealth>();
// 如果没有手动指定,尝试自动获取
if (healthBar == null)
{
healthBar = GetComponent<WorldHealthBar>();
}
}
private void Start()
{
// 初始化进度条(使用能量条显示产出进度)
if (healthBar != null)
{
healthBar.maxEnergy = 100f;
healthBar.currentEnergy = 0f;
}
}
private void Update()
{
if (GoldSystem.Instance == null)
if (GoldManager.Instance == null) return;
productionTimer += Time.deltaTime;
// 更新进度条
if (healthBar != null)
{
return;
float progress = Mathf.Clamp01(productionTimer / productionInterval);
healthBar.currentEnergy = progress * 100f;
}
timer += Time.deltaTime;
if (buildingHealth != null)
// 达到产出时间
if (productionTimer >= productionInterval)
{
buildingHealth.SetProductionProgress(timer / productionInterval);
}
while (timer >= productionInterval)
{
timer -= productionInterval;
GoldSystem.Instance.AddGold(goldPerTick);
ProduceGold();
productionTimer = 0f;
}
}
private void ProduceGold()
{
if (GoldManager.Instance != null)
{
GoldManager.Instance.AddGold(goldPerProduction);
Debug.Log($"{gameObject.name} 产出金币 +{goldPerProduction}");
// 可以在这里播放特效和音效
// TODO: 添加金币产出特效
}
}
// 在编辑器中显示信息
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position + Vector3.up * 2f, 0.5f);
}
}