private void Start() { health = maxHealth; fuel = maxFuel; ShipHealthUpdated?.Invoke(health); ShipFuelUpdated?.Invoke(fuel); ShipUpgradeManager.FuelCapUpgraded += OnUpgradeFuelCap; ShipUpgradeManager.FuelDrainUpgraded += OnFuelDrainUpgraded; ShipUpgradeManager.DamageMultiplierUpgraded += OnDamageMultiplierUpgraded; }
public void TakeDamage(float rawDamage) { health -= Mathf.RoundToInt(rawDamage * damageMultiplier); if (health <= 0) { health = 0; isDead = true; ShipHasDied?.Invoke(isDead); StartCoroutine(HandleRespawn(respawnTime)); } ShipHealthUpdated?.Invoke(health); }
private IEnumerator HandleRespawn(float timer) { yield return(new WaitForSeconds(timer)); health = maxHealth; fuel = maxFuel; transform.parent.position = respawnPoint.position; transform.parent.rotation = respawnPoint.rotation; isDead = false; ShipHealthUpdated?.Invoke(health); ShipFuelUpdated?.Invoke(fuel); ShipHasRespawned?.Invoke(); }
// Repairs and Refuels the ship each call. Checks if both fuel and health are // full, and returns true if R&R is complete, and false if R&R needs to continue. public bool RepairAndRefuel() { health = Mathf.Clamp(health + repairPerTick, 0, maxHealth); fuel = Mathf.Clamp(fuel + refuelPerTick, 0, maxFuel); ShipFuelUpdated?.Invoke(fuel); ShipHealthUpdated?.Invoke(health); if (health == maxHealth && fuel == maxFuel) { return(true); } else { return(false); } }