Unity -简单键鼠事件
“Test_03”
KeyTest
键鼠事件每帧都要监听,要放在Update()中处理
public class KeyTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// 【鼠标点击事件】 0左键、1右键、2中键(滚轮)
// 按下鼠标左键
if (Input.GetMouseButtonDown(0))
{
Debug.Log("点击鼠标左键");
}
// 持续按下鼠标左键
if (Input.GetMouseButton(0))
{
Debug.Log("持续按下了鼠标左键");
}
if (Input.GetMouseButtonUp(0))
{
Debug.Log("抬起了鼠标左键");
}
// 【键盘点击事件】
// 按下按键
if (Input.GetKeyDown(KeyCode.A))
{
Debug.Log("按下了A键");
}
// 持续按下按键
if (Input.GetKey(KeyCode.A))
{
Debug.Log("持续按下了A键");
}
// 抬起按键
if (Input.GetKeyUp(KeyCode.A))
{
Debug.Log("松开了A键");
}
}
}
原文地址:https://blog.csdn.net/qq_44897391/article/details/135702418
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!