using UnityEngine; using gameManager /* This is obviously a cut down version of what an enemy class would and should contain. Only functions and logic related to enemies taking damage. */ public class Takenenemy : MonoBehaviour { public EnemyType enemyType; // The type of enemy public EnemySkin enemySkin; // The enemies rended appearance private double healthPoints; // Hitpoints for conventional weapons private double darknessHealthPoints; // Hitpoints for light based weapons //Methods /* Initialize the Taken's health using the enemies type and the games current difficulty setting. */ private void Start() { /* Get the difficulty cofactor as a float from the Game Manager I don't cover the GameManager here so getDifficultyFloat() returns a value corresponding to the current difficulty. On the easiest setting that could be 1.0 while the hardest making the enemies twice as durable would be 2.0. */ private float difficultyCofactor = GameManager.getDifficultyFloat(); // // Assign the Taken's normal Hitpoint value healthPoints = enemyType.health * difficultyCofactor; // Assign the Taken's normal Hitpoint value darknessHealthPoints = enemyType.health * difficultyCofactor; } /* If the Taken's health reaches zero they get destroyed Here I'm just using Unity's generic object destroy function but in reality there is a whole process and animation when and how a Taken is destroyed. */ private void LateUpdate() { if (healthPoints <= 0) { destroy(); } } /* Inflict conventional weapons damage The takeDamage() function is called then the player hits a Taken with a firearm. If the Taken's shield of darkness is gone then the Taken will directly. */ public void takeDamage(float dmg) { if (darknessHealthPoints <= 0) { healthPoints -= dmg; } } /* Inflict light-based weapons damage The takeLightDamage() function is called when the player uses a light based weapon like their flashlight or flares. These only do damage to the Taken's shield and only if the shield is still active */ public void takeLightDamage(float dmg) { if (darknessHealthPoints <= 0) { darknessHealthPoints -= dmg; } } /* Inflict explosive damage The takeExplosivesDamage() function simple sets the Taken's healthPoints to Zero. In-game explosives (flash-bang grenades & flare gun shots) generally deal fatal damage. */ public void takeExplosivesDamage() { healthPoints = 0; } }