SliderIndicator.cs 541 B

1234567891011121314151617181920212223
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class SliderIndicator : MonoBehaviour
  6. {
  7. public Slider slider;
  8. public Text text;
  9. void Start()
  10. {
  11. slider.onValueChanged.AddListener(OnChanged);
  12. text.text = slider.value.ToString();
  13. }
  14. void OnChanged(float value){
  15. text.text = slider.value.ToString();
  16. }
  17. void OnValidate(){
  18. if(GetComponent<Text>()!=null && text==null)
  19. text = GetComponent<Text>();
  20. }
  21. }