using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.UI;

public class SliderAnim : MonoBehaviour
{
    public float animSpeed = 1;
    private float _targetValue = 0;
    private Slider slider;

    private Health health;

    void Start(){
        slider = GetComponent<Slider>();
        slider.value = _targetValue;
        health = GetComponentInParent<Health>();
        health.hit.AddListener(delegate{ChangeValue(health.maxHealth - health.GetCurrentHealth());} );
    }
    
    void Update(){
        if(slider.value != _targetValue){
            slider.value = Mathf.MoveTowards(slider.value, _targetValue, animSpeed*Time.deltaTime);
        }
    }
    public void ChangeValue(float targetValue){
        _targetValue = targetValue;
   }
   
}
