Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class HealthBar : MonoBehaviour
- {
- public Slider slider;
- public Image fill;
- public HitButton hitButton;
- private float _actualHealth;
- public void Damage(int damageAmount)
- {
- if (_actualHealth > 0)
- {
- _actualHealth -= damageAmount;
- }
- }
- public void Heal(int healAmount)
- {
- if (_actualHealth < 100)
- {
- _actualHealth += healAmount;
- }
- }
- private void Start()
- {
- slider.value = 100f;
- _actualHealth = 100f;
- }
- private void Update()
- {
- slider.value = Mathf.Lerp(slider.value, _actualHealth, 2 * Time.deltaTime);
- }
- }
Add Comment
Please, Sign In to add comment