「Unity」键盘、鼠标,检测按键输入事件

必须在Update()方法中调用

 void Update()
    {
        //识别键盘输入
        //键盘A键按住
        //第一种方式 "a" 必须是小写字母
        if (Input.GetKey("a"))
        {
        }
        //第二种方式 KeyCode的枚举类型
        if (Input.GetKey(KeyCode.A))
        {
        }

        //键盘A按下瞬间
        if (Input.GetKeyDown("a"))
        {
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
        }

        //键盘A抬起瞬间
        if (Input.GetKeyUp("a"))
        {
        }
        if (Input.GetKeyUp(KeyCode.A))
        {
        }


        //识别鼠标输入
        //鼠标左键按住
        //int 0 (右键1 中键2)
        if (Input.GetMouseButton(0))
        {
        }

        //鼠标左键按下瞬间
        if (Input.GetMouseButtonDown(0))
        {
        }

        //鼠标左键抬起瞬间
        if (Input.GetMouseButtonUp(0))
        {
        }
    }

原创内容,转载请注明出处

http://www.cnblogs.com/777777-716/p/5003962.html 

posted @ 2015-04-22 17:08  万士辰  阅读(16528)  评论(0编辑  收藏  举报