unity3d中如何创建UI按钮功能
发布时间:2017-04-14 来源:查字典编辑
摘要:unity3d中通过对一个按钮的创建使用,从而了解unity3d中UI的使用。1、打开unity3d项目“GameObject”--“UI”...
unity3d中通过对一个按钮的创建使用,从而了解unity3d中UI的使用。

1、打开unity3d项目“GameObject”--“UI”--“Button”,创建一个按钮。

2、在“Rect Transform”下可以改变按钮的布局位置大小等。

3、在“Image (Script)”与“Button(Script)”中可以更详细的设置按钮的颜色等效果。

4、展开Button在其中的“Text”中的“Text(Script)”中可以设置按钮显示文字信息。

5、新建一个文件夹“Script”在里面新建一个“Button_test”的脚本,打开后在里面添加一个方法
public void Click_test(){
Debug.Log("点击测试");
}

6、把编辑好的“Button_test”脚本添加到场景中的Button上。

7、点击“On Click ()”下的“+”添加,然后Object中选择添加“Button”。

8、点击“No Function”选择“Button_test”--“Click_test ()”,保存后运行,点击按钮旧可以调用脚本中我们定义的Click_test ()方法,输出“点击测试”。

注意事项:
脚本中定义的方法必须是public的,否则找不到。