OwlyOwl

HealthBarishe

May 25th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class HealthBar : MonoBehaviour
  7. {
  8.  
  9.     public Slider slider;
  10.     public Image fill;
  11.     public HitButton hitButton;
  12.     private float _actualHealth;
  13.  
  14.     public void Damage(int damageAmount)
  15.     {
  16.         if (_actualHealth > 0)
  17.         {
  18.             _actualHealth -= damageAmount;
  19.         }
  20.     }
  21.  
  22.     public void Heal(int healAmount)
  23.     {
  24.         if (_actualHealth < 100)
  25.         {
  26.             _actualHealth += healAmount;
  27.         }
  28.     }
  29.  
  30.     private void Start()
  31.     {
  32.         slider.value = 100f;
  33.         _actualHealth = 100f;
  34.     }
  35.  
  36.     private void Update()
  37.     {
  38.         slider.value = Mathf.Lerp(slider.value, _actualHealth, 2 * Time.deltaTime);
  39.     }
  40.  
  41. }
Add Comment
Please, Sign In to add comment