void Update() { /*The first if block checks if the Inivincibility Perk was enabled. * If so, we start our timer and once it exceeds our time period, we * disable the Perk effect and reset our timer.*/ if (invincible.GetInvincibilityStatus()) { healthBar.SetFillColor(); InvincibilityTimer += Time.deltaTime; if (InvincibilityTimer > InvincibilityDuration) { invincible.SetInvincibility(false); InvincibilityTimer = 0.0f; healthBar.RevertFillColor(); } } /*The second if block checks if the Invincibility Perk was told to respawn, if so, * we start our respective timer, and once it exceeds our time period, we respawn the perk. */ if (invincible.GetInvincibilityRespawnStatus()) { InvincibilityRespawnTimer += Time.deltaTime; if (InvincibilityRespawnTimer > InvincibilityRespawnDuration) { invincible.SetInvincibilityRespawn(false); InvincibilityRespawnTimer = 0.0f; InvincibilityBox.gameObject.SetActive(true); } } /*The third if block checks if the Health Perk was told to respawn, if so, * we start out respective timer, and once it exceeds our time period, we respawn the perk.*/ if (healthSystem.GetHealthRespawnStatus()) { HealthRespawnTimer += Time.deltaTime; if (HealthRespawnTimer > HealthRespawnDuration) { healthSystem.SetHealthRespawn(false); HealthRespawnTimer = 0.0f; HealthBox.gameObject.SetActive(true); } } /*The fourth if block checks if the Regenerate Perk was told to respawn, if so, we start * both timers. The nested if checks if invincibility is active, if the regenerationlength timer is greater than our * set interpolation period, and if our counter is less than 10. Essentially, when our code notices that the Regeneration Perk * was triggered, a timer starts and this timer is compared to our interpolation const time (this enables us to choose how often the * player should get healed. For example, if interpolation period is = 1.0f, then we will heal every 1 second.) The counter is * used to keep track of how many times we've entered the "healing" stage. We can use this to limit how long the effect can last. * For example, if interpolation period = 1.0f and our counter restriction is 10, then that means the effect will last for 10 second. (10/1) * Once all 3 conditions are met, we increase counter, Reset our regeneration timer, heal, update the health bar, and keep the color * of our health bar silver, because we still have invincibility. * Now we check the else if condition, which is the same as before instead of the invincibility check. We continue with * the same proceedings the only difference is that we do not keep the color of the health bar silver. * This whole time the RegenerateHealthRespawn timer has been increasing, the finl if checks is this value has * exceeded our set time, if so we respawn the perk, and reset all respective variables. */ if (healthSystem.GetRegenerateRespawnStatus()) { RegenerateHealthRespawnTimer += Time.deltaTime; RegenerationTimer += Time.deltaTime; if (invincible.GetInvincibilityStatus() && RegenerationTimer >= interpolationPeriod && counterRegenerate <= maxRegenerate) { counterRegenerate++; RegenerationTimer = 0.0f; healthSystem.Heal(10); healthBar.SetHealth(healthSystem.GetHealth()); healthBar.SetFillColor(); } else if (RegenerationTimer >= interpolationPeriod && counterRegenerate <= maxRegenerate) { counterRegenerate++; RegenerationTimer = 0.0f; healthSystem.Heal(10); healthBar.SetHealth(healthSystem.GetHealth()); } if (RegenerateHealthRespawnTimer > RegenerationRespawnDuration) { healthSystem.SetRegenerateRespawn(false); RegenerateHealthRespawnTimer = 0.0f; RegenerationTimer = 0.0f; RegenerateBox.gameObject.SetActive(true); counterRegenerate = 0; } } /*Same concept as Regenerate above, except that it is tailored for the Degenerate Perk (damage instead of heal) * Also, when we are invincible damage will not be taken from this anti-perk*/ if (healthSystem.GetDegenerateRespawnStatus()) { DegenerateHealthRespawnTimer += Time.deltaTime; DegenerationTimer += Time.deltaTime; if (invincible.GetInvincibilityStatus() && DegenerationTimer >= interpolationPeriod && counterDegenerate <= maxDegenerate) { counterDegenerate++; DegenerationTimer = 0.0f; } else if (DegenerationTimer >= interpolationPeriod && counterDegenerate <= maxDegenerate) { counterDegenerate++; DegenerationTimer = 0.0f; healthSystem.Damage(5); healthBar.SetHealth(healthSystem.GetHealth()); } if (DegenerateHealthRespawnTimer > DegenerationRespawnDuration) { healthSystem.SetDegenerateRespawn(false); DegenerateHealthRespawnTimer = 0.0f; DegenerationTimer = 0.0f; DegenerateBox.gameObject.SetActive(true); counterDegenerate = 0; } } /*WORK IN PROGRESS * if (healthSystem.GetMaxStatus()) * { * MaxHealthRespawn += Time.deltaTime; * if (MaxHealthRespawn > 5.0f) * { * healthSystem.DisableMaxRespawn(); * MaxHealthRespawn = 0.0f; * MaxHealthBox.gameObject.SetActive(true); * } * }*/ }