Unity 键盘事件

来源:互联网 发布:手机怎么举报淘宝卖家 编辑:程序博客网 时间:2024/04/28 20:37


按下事件

void Update (){if(Input.GetKeyDown(KeyCode.W)){Debug.Log("W");}if(Input.GetKeyDown(KeyCode.S)){Debug.Log("S");}if(Input.GetKeyDown(KeyCode.A)){Debug.Log("A");}if(Input.GetKeyDown(KeyCode.D)){Debug.Log("D");}if(Input.GetKeyDown(KeyCode.Space)){Debug.Log("Space");}}


抬起事件

if(Input.GetKeyUp(KeyCode.Space)){Debug.Log("D");}


鼠标事件 0代表左,1代表右键,2代表中间键

if(Input.GetMouseButtonDown(0)){Debug.Log("left"+ Input.mousePosition);}if(Input.GetMouseButtonUp(1)){Debug.Log("Right" + Input.mousePosition);}if(Input.GetMouseButton(2)){Debug.Log("Center" + Input.mousePosition);}


原创粉丝点击