Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BossHealthManager : MonoBehaviour
- {
- public int enemyHealth; // How much health the enemy has
- public GameObject deathParticle; // Effect when enemy dies
- public int pointsForKillingEnemy; // Points to add when the enemy is killed
- public GameObject bossPrefab; // Prefab for the boss
- public float minSize; // Minimum size for the boss to stop dividing
- public int initialHealth; // Initial health for clones
- void Start()
- {
- if (enemyHealth <= 0)
- {
- enemyHealth = initialHealth; // Set initial health if not already set
- }
- }
- void Update()
- {
- if (enemyHealth <= 0) // If the enemy health is less than or equal to 0
- {
- Debug.Log("Enemy health is zero or less. Triggering division.");
- Instantiate(deathParticle, transform.position, transform.rotation); // Spawn the death effect
- ScoreManager.AddPoints(pointsForKillingEnemy); // Add points to score
- if (transform.localScale.x > minSize && transform.localScale.y > minSize) // Check if the boss size is greater than the minimum size
- {
- float newScaleX = transform.localScale.x * 0.5f; // Calculate the new size for the clones
- float newScaleY = transform.localScale.y * 0.5f;
- Debug.Log("Creating clones with new scale: " + newScaleX + ", " + newScaleY);
- // Instantiate clone1 and set its scale and health
- GameObject clone1 = Instantiate(bossPrefab, new Vector3(transform.position.x + 0.5f, transform.position.y, transform.position.z), transform.rotation);
- Debug.Log("Clone1 position: " + clone1.transform.position);
- clone1.transform.localScale = new Vector3(newScaleX, newScaleY, transform.localScale.z);
- Debug.Log("Clone1 scale: " + clone1.transform.localScale);
- clone1.GetComponent<BossHealthManager>().enemyHealth = initialHealth; // Set health of boss clone1
- // Instantiate clone2 and set its scale and health
- GameObject clone2 = Instantiate(bossPrefab, new Vector3(transform.position.x - 0.5f, transform.position.y, transform.position.z), transform.rotation);
- Debug.Log("Clone2 position: " + clone2.transform.position);
- clone2.transform.localScale = new Vector3(newScaleX, newScaleY, transform.localScale.z);
- Debug.Log("Clone2 scale: " + clone2.transform.localScale);
- clone2.GetComponent<BossHealthManager>().enemyHealth = initialHealth; // Set health of boss clone2
- }
- else
- {
- Debug.Log("Boss has reached minimum size and will not divide further.");
- }
- Destroy(gameObject); // Destroy the original enemy
- }
- }
- public void giveDamage(int damageToGive)
- {
- enemyHealth -= damageToGive;
- Debug.Log("Enemy takes damage: " + damageToGive + ". Current health: " + enemyHealth);
- GetComponent<AudioSource>().Play();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement