
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 ()方法,输出“点击测试”。
var customSkin:GUISkinfunction OnGUI () {
if(GUI.Button(Rect(Screen.width/2-50, Screen.height/2+200, 100,50), "Play game"))
{
print("You clicked me")
Application.LoadLevel(1)
}
//GUI.Button(Rect(Screen.width/2-50, Screen.height/2+260, 100,50), "exit game")
if(GUI.Button(Rect(Screen.width/2-50, Screen.height/2+260, 100,50), "exit game"))
{
print("You clicked me")
Application.LoadLevel(2)
}
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)