霸气的昵称 发表于 2012-6-15 17:53

Unity3D中有关按钮的一些用法实例代码

function OnGUI () {

//一个最简单的按钮
if (GUILayout.Button("button"))
print("u pressed button");

//只认可左键点击
if (GUILayout.Button("button00") && Event.current.button == 0)
print("u pressed button00 with left button");

//点击或输入a
if (GUILayout.Button("button01") || (Event.current.type == EventType.keyDown && Event.current.character == "a") )
print("u pressed button01 Or input a");

//Ctrl + 左键点击
if (GUILayout.Button("button02") && Input.GetKey (KeyCode.LeftControl) && Event.current.button == 0)
print("u pressed button02 with left button");


}{:soso__6235880048239246314_3:}
如果想一直触发按钮press down 像 GetKey(KeyCode.W) 一样,可用RepeatButton 。

cgjch8 发表于 2017-2-28 15:08

好帖就是要顶

@笑笑Doria@ 发表于 2017-2-28 15:42

难得一见的好帖

xuxudefeng 发表于 2017-2-28 15:25

说的非常好

@笑笑Doria@ 发表于 2017-2-28 14:58

很好哦

ljhunity3d455 发表于 2017-2-28 14:57

不错不错

fu1393391287 发表于 2017-3-10 19:59

顶顶多好

weisen 发表于 2017-3-10 20:16

难得一见的好帖

seungsoo 发表于 2017-3-10 20:43

说的非常好

三杀 发表于 2017-3-10 20:08

很好哦
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: Unity3D中有关按钮的一些用法实例代码