SliderText.cs 899 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. namespace KairoEngine.UI
  7. {
  8. public class SliderText : MonoBehaviour
  9. {
  10. public TextMeshProUGUI text;
  11. public string suffix = "%";
  12. public float multiplier = 100;
  13. public Slider slider;
  14. public void OnEnable()
  15. {
  16. slider.onValueChanged.AddListener(delegate {UpdateText(); });
  17. }
  18. void OnDisable()
  19. {
  20. slider.onValueChanged.RemoveListener(delegate {UpdateText(); });
  21. }
  22. void Start()
  23. {
  24. UpdateText();
  25. }
  26. public void UpdateText()
  27. {
  28. float value = slider.value * multiplier;
  29. value = value < 0.6 ? 0 : Mathf.CeilToInt(value);
  30. text.text = $"{(int)value}{suffix}";
  31. }
  32. }
  33. }