unity中锁定鼠标移动&&隐藏鼠标&&强制是鼠标移动到某一位置

unity中锁定鼠标移动&&隐藏鼠标&&强制是鼠标移动到某一位置

[System.Runtime.InteropServices.DllImport("user32.dll")] //引入dll
public static extern int SetCursorPos ( int x , int y );

void Update()
{
  SetMouseToAnyOfScreenPosition();
}

void SetMouseToAnyOfScreenPosition()
{
  SetCursorPos ( 20 , 20 );//放在update中,每帧调用,强制设置坐标
  Cursor . visible = false;//隐藏鼠标
}

使用心得:
仅仅在Srart里调一下

//true是显示,false是隐藏
Cursor.visible = false;

就可以实现隐藏鼠标了,并不需要每帧去调用

posted @ 2022-06-22 18:05  哒哒哒~~~  阅读(358)  评论(0编辑  收藏  举报