【Unity】脚本:监听鼠标键盘事件
如下:
void Update()
{
//识别键盘输入
//键盘A键按住
//第一种方式 "a" 必须是小写字母
if (Input.GetKey("a"))
{
Debug.Log("a");
}
//第二种方式 KeyCode的枚举类型
if (Input.GetKey(KeyCode.A))
{
Debug.Log("A");
}
//键盘A按下瞬间
if (Input.GetKeyDown("a"))
{
Debug.Log("a");
}
if (Input.GetKeyDown(KeyCode.A))
{
Debug.Log("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))
{
}
}
Love for Ever Day