private void SetBuildingButton(ButtonData buttonData) { int price = selectedTile.Building.Data.RepairCost; float percentage = buildingHealth.CurrentBuildingHealthPercentage; price = (int)((1 - percentage) * price); buttonData.PriceText.text = price.ToString(); buildingHealth.SetBuildingHealthBar(buttonData.healthBar); Button button = buttonData.Button; if (!CanAffort(price)) { BlockButton(button, true); return; } BlockButton(button, false); SetButton(button, OnClick); void OnClick() { ReduceMoney(price); buildingHealth.ResetBuildingHealth(); } }
private void SetupRepairButton(AbstractBuildingTile tile, AbstractMarketManager manager) { int price = tile.Building.Data.RepairCost; BuildingHealth buildingHealth = tile.Building.GetComponent <BuildingHealth>(); float percentage = buildingHealth.CurrentBuildingHealthPercentage; price = (int)((1 - percentage) * price); repairText.text = price.ToString(); if (!CanAffort(price)) { BlockButton(btnRepair); return; } UnblockButton(btnRepair); SetButton(btnRepair, OnClick); void OnClick() { ReduceMoney(price); buildingHealth.ResetBuildingHealth(); manager.CloseMarket(); } }