一,按鍵的按下抬起等識別方法
void Update () { int key1 = 0; int key2 = 0; if (Input.GetKeyDown (KeyCode.A)) { Debug.Log("A按下一次"); } if (Input.GetKey (KeyCode.A)) { //記錄按下的幀數,判斷特定按鍵按下不抬起 key1++; Debug.Log("A連按:" + key1+"幀"); } if (Input.GetKeyUp (KeyCode.A)) { //抬起后清空幀數 key1=0; Debug.Log("A按鍵抬起"); } if(Input.anyKeyDown) { //清空按下幀數,任意鍵按下識別方法,返回true key2=0; Debug.Log("任意鍵被按下"); } if(Input.anyKey) { //若保持任意鍵按下,這key2會一直執行++,知道按鍵被抬起 key2++; Debug.Log("任意鍵被長按"+key2+"幀"); } }
