void Update()
{
//监听键盘输入
if (Input.GetKeyDown(KeyCode.A))//KeyCode.A键盘A
{
Debug.Log("A键按下");
}
if (Input.GetKey(KeyCode.A))
{
Debug.Log("A键按下中");
}
if (Input.GetKeyUp(KeyCode.A))
{
Debug.Log("A键抬起");
}
//监听鼠标输入
if (Input.GetMouseButtonDown(0))
{
Debug.Log("鼠标左键按下入");
}
if (Input.GetMouseButton(0))
{
Debug.Log("鼠标左键按下入");
}
if (Input.GetMouseButtonUp(0))
{
Debug.Log("鼠标左键抬起");
}
//鼠标对应关系:0鼠标左键,1代表鼠标右键,2代表鼠标滚轮
if (Input.GetMouseButtonDown(0)){
Debug.Log("鼠标左键按下");
}
if (Input.GetMouseButtonDown(1))
{
Debug.Log("鼠标右键按下");
}
if (Input.GetMouseButtonDown(2))
{
Debug.Log("鼠标滚轮键按下");
}
}
文章详细描述了在Unity编程中如何使用Input类监听和处理键盘(A键)和鼠标(左键、右键、滚轮)的按下与抬起事件,展示了基本的用户输入管理。
947

被折叠的 条评论
为什么被折叠?



