private void Update() { healthValue = health; // sets the healthValue to the players current health shieldValue = currShieldHealth; // sets the shieldValue to the players current shield health if (gameOverTimer > 0) // If the Timer has been set in the Die() method... { gameOverTimer -= Time.deltaTime; // start counting down } if (cooldownInvulnerability > 0) { cooldownInvulnerability -= Time.deltaTime; // if cooldownInvulnerability still has time life, countdown timer } switch (currentHealthState) { case HealthState.Regular: // Do behavior for this state: shieldRender.enabled = false; // disable the shield render on the player if (currShieldHealth < maxShieldHealth) // If NOT shielding and shieldHealth < max... { currShieldHealth = currShieldHealth + .05f; // Regen shield health } if (currShieldHealth >= minShieldHealth) // If shieldHealth >= minimumHealth... { canShield = true; // Player can turn on shield... } else { canShield = false; } // ELSE, player can NOT shield // Transition to other states: if (!shielding && Input.GetButtonDown("Shield") && currShieldHealth > minUsableShieldHealth) // If NOT shielding, pressing Q, and currShieldHealth > minShieldHealth... { SoundBoard.PlayPlayerShieldOn(); currentHealthState = HealthState.Shielding; // switch to shielding state shielding = true; // set shielding to true } break; case HealthState.Shielding: // Do behavior for this state: shieldRender.enabled = true; // render the shield on the player // Transition to other states: if (shielding && Input.GetButtonDown("Shield")) // If shielding and pressing Q { SoundBoard.PlayPlayerShieldOff(); currentHealthState = HealthState.Regular; // switch to regular state shielding = false; // set shielding to false } break; } }
// Health behavior: public void TakeDamage(float amt) { if (cooldownInvulnerability > 0) { return; // still have i-frames, dont take damage } cooldownInvulnerability = .25f; // cooldown till you can take damage amt = BadBullet.damageAmount; if (amt < 0) { amt = 0; // Negative numbers ignored } damageTaken = true; // Tells the game that the player took damage if (shielding) // If player is shielding... { currShieldHealth -= amt; // Deal damage to the shield SoundBoard.PlayPlayerDamage(); if (currShieldHealth < 1) // If shield health is below 1... { SoundBoard.PlayPlayerShieldOff(); currentHealthState = HealthState.Regular; // Switch back to Regular HealthState shielding = false; // Turn off shield } } else { health -= amt; // If not shielding, deal damage to player health SoundBoard.PlayPlayerDamage(); } //if (health > 0) SoundEffectBoard.PlayDamage(); // plays damage audio if (health <= 0) { Die(); // if health drops to/below zero do Die method //SoundEffectBoard.PlayDie(); // plays death audio } damageTaken = false; // Player no longer taking damage }
void Update() { FollowPlayer(); AimAtMouse(); batteryValue = currBattery; // Sets the batteryValue to the tracked current battery if (timerSpawnBullet > 0) { timerSpawnBullet -= Time.deltaTime; // if the timer is GREATER THAN 0, countdown the timer } switch (currentPodState) // State Switcher { case PodState.Regular: // Regular State: Follows player, depletes battery // Behavior currBattery -= Time.deltaTime; // Battery drops over time podStatus.text = ("ONLINE"); // UI tells player the pod is online // Transition if (Input.GetButton("Fire1")) { currentPodState = PodState.Shooting; } // If player presses "Left Click", switch to Shooting state if (Input.GetButtonDown("FollowerPower")) // If player presses "F"... { SoundBoard.PlayPlayerShieldOff(); // Play Player Shield Off Sound currentPodState = PodState.Charging; // Switch to charging state } if (currBattery <= batteryMin) // if current battery is LESS THAN or EQUAL TO minimum battery... { SoundBoard.PlayPlayerShieldOff(); // Play player shield off sound currentPodState = PodState.Charging; // switch to charging state } break; case PodState.Shooting: // Shooting State: Follows player, Shoots when player shoots, depletes battery // Behavior currBattery -= Time.deltaTime; // battery drops over time SpawnGoodBullet(); podStatus.text = ("FIRING"); // UI tells player the pod is firing // Transition if (!Input.GetButton("Fire1")) { currentPodState = PodState.Regular; } // If player is not left clicking, switch to regular state if (currBattery <= batteryMin) // if current battery is LESS THAN or EQUAL TO minimum battery... { SoundBoard.PlayPlayerShieldOff(); // Player player shield off sound currentPodState = PodState.Charging; // switch to charging state } break; case PodState.Charging: // Charging State: Follows player, charges battery // Behavior currBattery += Time.deltaTime * 1.5f; // current battery increases over time podStatus.text = ("CHARGING"); // UI tells player the pod is charging // Transition if (Input.GetButtonDown("FollowerPower")) // If player presses "F" { SoundBoard.PlayPlayerShieldOn(); // Play player shield on sound currentPodState = PodState.Regular; // Switch to regular state } if (currBattery >= batteryMax) { currentPodState = PodState.Off; } // If current battery is GREATER THAN or EQUAL TO maximum battery, switch to Off state break; case PodState.Off: // Off State: Do nothing // Behavior podStatus.text = ("OFFLINE"); // UI tells player the pod is offline // Transition if (Input.GetButtonDown("FollowerPower")) // If player presses "F" { SoundBoard.PlayPlayerShieldOn(); // Play player shield on sound currentPodState = PodState.Regular; // Switch to regular state } break; } }