Ejemplo n.º 1
0
    private void Start()
    {
        health = maxHealth;
        fuel   = maxFuel;

        ShipHealthUpdated?.Invoke(health);
        ShipFuelUpdated?.Invoke(fuel);

        ShipUpgradeManager.FuelCapUpgraded          += OnUpgradeFuelCap;
        ShipUpgradeManager.FuelDrainUpgraded        += OnFuelDrainUpgraded;
        ShipUpgradeManager.DamageMultiplierUpgraded += OnDamageMultiplierUpgraded;
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    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();
    }
Ejemplo n.º 4
0
    // 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);
        }
    }