12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class hp : MonoBehaviour
- {
-
- [HideInInspector] public float PlayerHP;
- [Header("Полоска здоровья")]
- public Image HPImage;
-
- void Start()
- {
- PlayerHP = 100;
- }
- // Update is called once per frame
- void Update()
- {
- HPImage.fillAmount = PlayerHP/100;
- if(PlayerHP<=0 && this.gameObject.tag=="Player")
- {
- SceneManager.LoadScene(0);
- }
- if (PlayerHP <= 0 && this.gameObject.tag == "Enemy")
- {
- Destroy(this.gameObject);
- }
- }
- public void SetDamage(float damage)
- {
- PlayerHP -= damage;
- }
- public void SetHealth(float health)
- {
- PlayerHP += health;
- }
- }
|