rabidus-test/Assets/Scripts/UIProgressBar.cs

52 lines
1.1 KiB
C#
Raw Normal View History

2023-09-04 12:48:24 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIProgressBar : MonoBehaviour
{
2023-09-11 15:44:17 +03:00
[SerializeField] private Image _progressImage;
[SerializeField] private bool _useColors = false;
[SerializeField] private float _maxValue;
[SerializeField][Range(0, 1)] private float _startValue;
[Space]
[Header("Color setup")]
[SerializeField] private Color _startColor;
[SerializeField] private Color _endColor;
2023-09-04 12:48:24 +03:00
private float _clampedValue = 0;
public float ClampedValue
{
get => _clampedValue;
set
{
2023-09-11 15:44:17 +03:00
if (_useColors)
{
_progressImage.color = Color.Lerp(_startColor, _endColor, value);
}
2023-09-04 12:48:24 +03:00
_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);
}
}