「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 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM