using UnityEngine; public class GoldMine : MonoBehaviour { [Header("产出配置")] [Min(0)] public int goldPerTick = 5; [Min(0.1f)] public float productionInterval = 3f; private float timer; private BuildingHealth buildingHealth; private void Awake() { buildingHealth = GetComponent(); } private void Update() { if (GoldSystem.Instance == null) { return; } timer += Time.deltaTime; if (buildingHealth != null) { buildingHealth.SetProductionProgress(timer / productionInterval); } while (timer >= productionInterval) { timer -= productionInterval; GoldSystem.Instance.AddGold(goldPerTick); } } }