Article directory
1. Introduction
Unity detection brief summary has been pressed function summary
2. The mouse has been pressed, pressed for a moment, released for a moment
if (Input.GetMouseButtonDown(0))
{
// 在鼠标左键被按下一瞬间执行的代码
}
if (Input.GetMouseButton(0))
{
// 在鼠标左键一直被按着时执行的代码
}
if (Input.GetMouseButtonUp(0))
{
// 在鼠标左键被松开一瞬间执行的代码
}
3. A key on the keyboard has been pressed, pressed for a moment, released for a moment
if (Input.GetMouseButtonUp(0))
{
// 在鼠标左键被松开一瞬间执行的代码
}
if (Input.GetKeyDown(KeyCode.Space))
{
// 在空格键被按下一瞬间执行的代码
}
if (Input.GetKeyUp(KeyCode.Space))
{
// 在空格键被松开一瞬间执行的代码
}
4. Summary
一直按着,用getkey()
一瞬间,用“getkeyup()”和“getkeydown()”
Input.GetKey:检测某个按键是否一直被按下。
Input.GetKeyDown: Check whether a key is pressed in the current frame.
Input.GetKeyUp: Check whether a key is released in the current frame.
Input.GetAxis: Get the value of the input axis, such as the up, down, left, and right arrows on the keyboard or the joystick of the handle.
Input.GetButton: Detects whether a button is pressed.
Input.GetButtonDown: Check whether a button is pressed in the current frame.
Input.GetButtonUp: Check whether a button is released in the current frame.
Input.GetMouseButton: Detect whether the left, right or middle mouse button has been pressed.
Input.GetMouseButtonDown: Check whether the left, right or middle mouse button is pressed in the current frame.
Input.GetMouseButtonUp: Check whether the left, right or middle mouse button is released in the current frame.