1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- namespace KairoEngine.UI
- {
- public class SliderText : MonoBehaviour
- {
- public TextMeshProUGUI text;
- public string suffix = "%";
- public float multiplier = 100;
- public Slider slider;
-
- public void OnEnable()
- {
- slider.onValueChanged.AddListener(delegate {UpdateText(); });
- }
- void OnDisable()
- {
- slider.onValueChanged.RemoveListener(delegate {UpdateText(); });
- }
- void Start()
- {
- UpdateText();
- }
-
- public void UpdateText()
- {
- float value = slider.value * multiplier;
- value = value < 0.6 ? 0 : Mathf.CeilToInt(value);
- text.text = $"{(int)value}{suffix}";
- }
- }
- }
|