hp.cs 870 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. public class hp : MonoBehaviour
  7. {
  8. [HideInInspector] public float PlayerHP;
  9. [Header("Полоска здоровья")]
  10. public Image HPImage;
  11. void Start()
  12. {
  13. PlayerHP = 100;
  14. }
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. HPImage.fillAmount = PlayerHP/100;
  19. if(PlayerHP<=0 && this.gameObject.tag=="Player")
  20. {
  21. SceneManager.LoadScene(0);
  22. }
  23. if (PlayerHP <= 0 && this.gameObject.tag == "Enemy")
  24. {
  25. Destroy(this.gameObject);
  26. }
  27. }
  28. public void SetDamage(float damage)
  29. {
  30. PlayerHP -= damage;
  31. }
  32. public void SetHealth(float health)
  33. {
  34. PlayerHP += health;
  35. }
  36. }