Advertisement
kadyr

Untitled

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