using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UIProgressBar : MonoBehaviour { [SerializeField] private Image _progressImage; [SerializeField] private float _maxValue; [SerializeField][Range(0, 1)] private float _startValue; [Space] [Header("Color setup")] [SerializeField] private bool _useColors = false; [SerializeField] private Color _startColor; [SerializeField] private Color _endColor; private float _clampedValue = 0; public float ClampedValue { get => _clampedValue; set { if (_useColors) { _progressImage.color = Color.Lerp(_startColor, _endColor, value); } _progressImage.fillAmount = value; } } private void Start() { ClampedValue = Mathf.Clamp01(_startValue); } public void ChangeValue(int value) { ClampedValue = Mathf.Clamp01(value / _maxValue); } public void ChangeValue(float value) { ClampedValue = Mathf.Clamp01(value / _maxValue); } }