public void RepairTurret() { if (!isDamaged) { // If turret is not damaged print("Turret is not damaged"); return; } // Check Player has enough Currency if (PlayerStats.Money < turretBlueprint.GetRepairAmount()) { print("Not Enough Money to Upgrade"); return; } // Get Turret component var turretScript = turret.GetComponent <Turret>(); if (isDestroyed) { // Take away money PlayerStats.Money -= turretBlueprint.GetRepairAmount(); print("That full repair cost $" + turretBlueprint.GetRepairAmount()); } else if (isDamaged) { PlayerStats.Money -= turretBlueprint.GetRepairAmount(turretScript.StartHealth, turretScript.Health); print("That partial repair cost $" + turretBlueprint.GetRepairAmount(turretScript.StartHealth, turretScript.Health)); } // Repair Turret turretScript.RepairTurret(); isDamaged = false; if (!isDestroyed) { return; } isDestroyed = false; // Change Materials to turret Color turret.transform.GetChild(0).transform.GetChild(0).GetComponent <Renderer>().material.color = turretRepairColor; // Repeating Function checking turrets health InvokeRepeating(nameof(CheckForDamage), 2f, 0.2f); }
public void RepairTurret() { if (turretBlueprint == null) { return; } if (NS_GameManager.Money < turretBlueprint.GetRepairAmount() || turretHealth == 1) //>= turret.GetComponent<NS_Turret>().startHealth) { a_Audio.clip = error; a_Audio.PlayOneShot(error); Debug.Log("Not enough money"); return; } if (turretHealth < 1 && turretHealth > 0.5f) { NS_GameManager.Money -= turretBlueprint.GetRepairAmount(); NS_GameManager.MoneyChanged(); turret.GetComponent <NS_Turret>().health = turretStartingHealth; a_Audio.clip = upgradeMade; a_Audio.PlayOneShot(upgradeMade); GameObject repairEffect = (GameObject)Instantiate(repairParticle, GetBuildPosition(), Quaternion.identity); Destroy(repairEffect, 3f); } else if (turretHealth < 0.5f) { NS_GameManager.Money -= turretBlueprint.GetRepairAmount() * 2; NS_GameManager.MoneyChanged(); turret.GetComponent <NS_Turret>().health = turretStartingHealth; a_Audio.clip = upgradeMade; a_Audio.PlayOneShot(upgradeMade); GameObject repairEffect = (GameObject)Instantiate(repairParticle, GetBuildPosition(), Quaternion.identity); Destroy(repairEffect, 3f); } }