Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HP : MonoBehaviour
  6. {
  7. [SerializeField] int maxHealth;
  8. int currentHealth;
  9. [SerializeField] GameObject destroyed;
  10.  
  11. private void Start()
  12. {
  13. currentHealth = maxHealth;
  14. }
  15. public void GetDamage(int dmg)
  16. {
  17. currentHealth -= dmg;
  18. if (currentHealth <= 0)
  19. {
  20. GameObject.Instantiate(
  21. destroyed,
  22. transform.position,
  23. transform.rotation,
  24. transform.parent
  25. );
  26. Destroy(gameObject);
  27. }
  28. }
  29. public string GetHealth()
  30. {
  31. return currentHealth + " / " + maxHealth;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement