1. 鍵盤事件css
public class keyboard : MonoBehaviour { private int pressTime = 0; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.GetKeyDown(KeyCode.A)) { Debug.Log("keyDown A"); } if (Input.GetKeyUp (KeyCode.A)) { Debug.Log("KeyUp A"); pressTime = 0; } if (Input.GetKey (KeyCode.W)) { Debug.Log("LongKeyPress Timer:" + pressTime); pressTime++; } if (Input.anyKey) { Debug.Log("any key LongPress"); } if (Input.anyKeyDown) { Debug.Log("any keydown"); } } }
組合鍵思路:
一旦玩家按下了某鍵後,便開啓時間計時,記錄一段時間內玩家的按鍵信息,而後與正確的比較,超時或者按錯一個失敗。
2. 鼠標按鍵事件
public class mouse : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown (0)) { Debug.Log("press down mouse left"); } if (Input.GetMouseButtonDown (1)) { Debug.Log("press down mouse right"); } if (Input.GetMouseButtonDown (2)) { Debug.Log("press down mouse middle"); } if (Input.GetMouseButtonUp (0)) { Debug.Log("press up mouse left"); } if (Input.GetMouseButton (0)) { //Input.mousePosition -->三維座標 Debug.Log("press long down left" + Input.mousePosition); } } }
3. 自定義事件html
自定義按鍵以組合的方式出現,能夠設置多個按鍵同時影響。 Edit—>Project Setting –> input this