rabidus-test/Assets/UISlider.cs

33 lines
657 B
C#
Raw Permalink Normal View History

2023-10-02 19:12:35 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UISlider : MonoBehaviour
{
[SerializeField] private TMPro.TextMeshProUGUI _text;
[SerializeField] private string _prefix;
private Slider _slider;
private void Awake()
{
_slider = GetComponent<Slider>();
}
private void OnEnable()
{
_slider.onValueChanged.AddListener(OnValueChange);
}
private void OnDisable()
{
_slider.onValueChanged.RemoveListener(OnValueChange);
}
private void OnValueChange(float value)
{
_text.SetText(_prefix + value);
}
}