Advertisement
kadyr

Untitled

Nov 6th, 2021
1,225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using BossFightGame.Scripts;
  2. using UnityEngine;
  3.  
  4. public class Enemy : MonoBehaviour
  5. {
  6.     public HealthSystem healthSystem = new HealthSystem(100);
  7.     protected GameObject player;
  8.     protected int damage;
  9.     private bool isDead;
  10.  
  11.     void Start()
  12.     {
  13.         healthSystem.onHealthChanged += OnHealthChanged;
  14.     }
  15.  
  16.     private void OnHealthChanged(int i)
  17.     {
  18.         if (i <= 0)
  19.         {
  20.             Death();
  21.         }
  22.     }
  23.  
  24.     public virtual void Move() { }
  25.  
  26.     public virtual void Attack() { }
  27.  
  28.     private void Death()
  29.     {
  30.         isDead = true;
  31.         GetComponent<Animator>().SetBool("death", isDead);
  32.         GetComponent<Enemy>().enabled = false;
  33.     }
  34.  
  35.     private void Awake()
  36.     {
  37.         player = FindObjectOfType<PlayerController>().gameObject;
  38.     }
  39.  
  40.     void Update()
  41.     {
  42.         if (player == null)
  43.             return;
  44.         if (!isDead)
  45.         {
  46.             Move();
  47.             Attack();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement