必須在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)) { } }
原創內容,轉載請注明出處