实验内容:
Button点击,则对应的Label显示点击后显示的内容,Slider通知Lable显示滑动的数值。
实验步骤:
1、新建场景,添加UIRoot。在panel下添加一个Lable和一个Button .
2、在Lable中显示内容,
3、在Button中添加一个事件,新建一个脚本,新建方法
public void DisplayInfo()
{
this.GetComponent<UILabel>().text = "Hello World";
}
将脚本添加到Label上。
4、在button的属性中有notify,将添加脚本的Label拖入notify中,并且调用DisplayInfo方法。
5、运行并点击Button观察label的变化。
Slider通知Lable显示滑动的数值:
1、新建一个slider,在原有脚本中加入一个新的方法
public UISlider slider;
public void DisplaySliderValue()
{
this.GetComponent<UILabel>().text = slider.value.ToString();
}
2、将slider拖入脚本中,
3、点击slider,将label拖入到notify中。选择displaySliderValue方法。
4、运行就可以看到panel中的数值变化。(可以用于音频改变)