unity3D获取和设置鼠标的位置

Unity3d本身并不能设置鼠标的位置,需要依赖系统库,最近在做MAC平台的开发,MAC下得方法还没找到,但是在windows下得方法如下:

//引用系统库

    [DllImport("User32")]
    private static extern bool SetCursorPos(int xint y);
    [DllImport("User32")]

    private static extern bool GetCursorPos(out POINT pt);


        if (Input.GetMouseButton(1)/* && !Input.GetMouseButton(0)*/)
        {

            if (Input.GetMouseButtonDown(1))
            {
                POINT pt;

                GetCursorPos(out pt);

                lastMouseX = pt.X;
                lastMouseY = pt.Y;

                Input.mousePosition{ }
            }

            //Screen.lockCursor = true;
            Screen.showCursor = false;
            SetCursorPos(lastMouseXlastMouseY);
         

//改变视角
            x += Input.GetAxis("Mouse X") * speed.x * 0.02f;
            y -= Input.GetAxis("Mouse Y") * speed.y * 0.02f;
            y = ClampAngle(yyMinLimityMaxLimit);
        }


你可能感兴趣的:(Unity3d,unity3d,鼠标,windows)