Unity基础之Input类详解

Input类允许我们通过键盘,鼠标,触摸屏等方式从用户那里接收输入

按键状态

Input.anyKey    按下任意键都会返回true

Input.anyKeyDown   只有在按下任意按键的那一帧会返回true

Input.GetKey(KeyCode key)        按下指定按键返回true

Input.GetKeyDown(KeyCode key)        在按下指定按键的那一帧返回true

Inpur.GetKeyUp(KeyCode key)        在指定按键被按下后抬起的那一帧返回true


 if(Input.anyKey) 
{
    Debug.Log("anyKey");
}

if(Input.anyKeyDown)
{
    Debug.Log("anyKeyDown");
}

if(Input.GetKey(KeyCode.Q))
{
    Debug.Log("Q");
}

if (Input.GetKeyDown(KeyCode.Q))
{
    Debug.Log("Q Down");
}

if (Input.GetKeyUp(KeyCode.Q))
{
    Debug.Log("Q Up");
}

按钮状态

Input.GetButton(string buttonName) 按下指定虚拟按钮就会返回true

Input.GetBunttonDown(string buttonName)     按下指定虚拟按钮的那一帧返回true

Input.GetBunttonUp(string buttonName)        松开指定虚

你可能感兴趣的:(unity,游戏引擎)