using System.Collections; using System.Collections.Generic; using UnityEngine; /* -------------------------------------- Project: Programing assessment Standard: 91906 (AS3.7) v.1 School: Tauranga Boys' College Author: Rauputu Noah Phizacklea Date: August 2024 Unity: 2021.3.18f --------------------------------------- */ public class BossHealth : MonoBehaviour { public int health = 500; // Boss's total health public HealthBar healthBar; // Reference to the health bar UI public GameObject deathEffect; // Prefab for the death effect public bool isInvulnerable = false; // Flag to check if the boss is invulnerable public GameObject gameCompleteDoor; // Reference to the door GameObject void Start() { // Initialize the game complete door as inactive at the start gameCompleteDoor.SetActive(false); // Activate the health bar when the boss is alive healthBar.gameObject.SetActive(true); } // Method to apply damage to the boss public void TakeDamage(int damage) { // If the boss is invulnerable, ignore the damage if (isInvulnerable) return; // Decrease boss's health and update the health bar health -= damage; healthBar.SetHealth(health); // If health drops below 200, trigger the enraged state if (health <= 200) { GetComponent().SetBool("isEnraged", true); } // If health is zero or less, call Die method if (health <= 0) { Die(); } } // Method to handle the boss's death void Die() { // Instantiate the death effect at the boss's position Instantiate(deathEffect, transform.position, Quaternion.identity); // Destroy the boss game object Destroy(gameObject); // Activate the door GameObject to signify level completion gameCompleteDoor.SetActive(true); // Deactivate the health bar since the boss is dead healthBar.gameObject.SetActive(false); } }