Eonirr

Enemy OOp

Feb 6th, 2026
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Enemy : MonoBehaviour
  4. {
  5. public float health = 100f;
  6. public float speed = 3f;
  7. public Transform target;
  8.  
  9. void Update()
  10. {
  11. Move();
  12. CheckDeath();
  13. }
  14.  
  15. void Move()
  16. {
  17. if (!target) return;
  18.  
  19. Vector3 dir = (target.position - transform.position).normalized;
  20. transform.position += dir * speed * Time.deltaTime;
  21. }
  22.  
  23. public void TakeDamage(float dmg)
  24. {
  25. health -= dmg;
  26. }
  27.  
  28. void CheckDeath()
  29. {
  30. if (health <= 0f)
  31. Destroy(gameObject);
  32. }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment