I found a better solution for this problem using PInvoke. This would work only on windows, but windows is the main platform that suffers from this problem I believe:
#if UNITY_STANDALONE_WIN
[DllImport("user32.dll")]
static extern bool ClipCursor(ref RECT lpRect);
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
#endif
public void Start()
{
RECT cursorLimits;
cursorLimits.Left = 0;
cursorLimits.Top = 0;
cursorLimits.Right = Screen.width - 1;
cursorLimits.Bottom = Screen.height - 1;
ClipCursor(ref cursorLimits);
}
↧