using UnityEngine;
public class SliderDemo : MonoBehaviour {
public void OnSliderValueChanged(float value) {
Debug.Log("Slider的值发生了变化+"+value);
}// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
using UnityEngine;
using UnityEngine.UI;
public class SliderDemo : MonoBehaviour {
public void OnSliderValueChanged(float value) {
Debug.Log("Slider的值发生了变化+"+value);
}
private Slider slider;
private void Awake()
{
slider = GetComponent<Slider>();
}
// Use this for initialization
void Start () {
//通过代码绑定UI的变值回调事件
slider.onValueChanged.AddListener(OnSliderValueChanged);
}
// Update is called once per frame
void Update () {
}
}