【Unity】腳本:監聽鼠標鍵盤事件


如下:

        void Update()
        {
            //識別鍵盤輸入
            //鍵盤A鍵按住
            //第一種方式 "a" 必須是小寫字母
            if (Input.GetKey("a"))
            {
                Debug.Log("a");
            }
            //第二種方式 KeyCode的枚舉類型
            if (Input.GetKey(KeyCode.A))
            {
                Debug.Log("A");
            }

            //鍵盤A按下瞬間
            if (Input.GetKeyDown("a"))
            {
                Debug.Log("a");
            }
            if (Input.GetKeyDown(KeyCode.A))
            {
                Debug.Log("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))
            {
            }
        }

 


免責聲明!

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



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