using UnityEngine; using System.Collections; public class ResourceCollector : MonoBehaviour { [Header("Что производит это здание")] public ResourceType resourceType; [Tooltip("База награды за клик (используется для расчета множителя уровня)")] public float amountPerClick = 10f; [Header("Параметры хранилища")] [Tooltip("Максимальная вместимость")] public float maxCapacity = 100f; [Tooltip("Текущий запас (меняется автоматически)")] public float currentStock = 0f; [Header("Уровень здания")] public int level = 1; public float perLevelMultiplier = 1.2f; private ResourceManager _manager; private bool isRecharging = false; void Awake() { _manager = ResourceManager.Instance; if (_manager == null) { Debug.LogError($"{gameObject.name}: ResourceManager не найден!"); enabled = false; return; } currentStock = 0f; } // НОВЫЙ МЕТОД: Чтобы UI мог спрашивать: "Сколько там сейчас?" public float GetCurrentStock() { return currentStock; } public float GetMaxCapacity() { return maxCapacity; } void OnMouseDown() { if (currentStock <= 0) { Debug.Log($"[КЛИК] {gameObject.name} пуст. Идет восстановление..."); return; } float finalAmount = amountPerClick * Mathf.Pow(perLevelMultiplier, level - 1); // Отдаем всё, что накопилось float reward = currentStock; _manager.AddResource(resourceType, reward); // СБРОС В НОЛЬ currentStock = 0f; Debug.Log($"[СБОР] Получено {reward:F1} {resourceType}. Запас сброшен в 0."); if (!isRecharging) { StartCoroutine(RechargeRoutine()); } } System.Collections.IEnumerator RechargeRoutine() { if (isRecharging) yield break; isRecharging = true; float rechargeRate = 5f; // Единиц в секунду while (currentStock < maxCapacity) { currentStock += rechargeRate * Time.deltaTime; if (currentStock > maxCapacity) currentStock = maxCapacity; yield return null; } isRecharging = false; Debug.Log($"[ГОТОВО] {gameObject.name} полностью заполнен!"); } public void Upgrade() { level++; Debug.Log($"[АПГРЕЙД] Уровень {level}"); } }