Advertisement
johnnygoodguy2000

EnemyHealthManager.cs

Apr 28th, 2024 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyHealthManager : MonoBehaviour
  6. {
  7.  
  8.     public int enemyHealth; // How much health the enemy has
  9.  
  10.     public GameObject deathPartical;// Effect when enemy dies
  11.     public int pointsForKillingEnemy; // Points to add when the enemy is killed
  12.  
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.        
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.        
  23.         if (enemyHealth <= 0)
  24.         {
  25.             Instantiate(deathPartical, transform.position, transform.rotation); // Spawn the death effect
  26.             ScoreManager.AddPoints(pointsForKillingEnemy); // Add points to score
  27.  
  28.             Destroy(gameObject); // Destroy the enemy
  29.         }
  30.     }
  31.  
  32.     public void giveDamage(int damageToGive)
  33.     {
  34.         enemyHealth -= damageToGive;
  35.         GetComponent<AudioSource>().Play();
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement