The linked code works. Do you have a crosshair as a Unity UI Image? Turn off the Raycast Target on it since that Image might be receiving mouse clicks and preventing input from being used for whatever’s underneath the crosshair.
The only problem with the code posted is that it makes the cursor visible even while locked on the center. It seems rapidly changing Cursor.lockState within the same frame doesn’t really work as expected.
UnityEngine.EventSystems.PointerInputModule, unfortunately, just assumes that we always want the UI to be disabled when Cursor.lockState == CursorLockMode.Locked, it doesn’t provide an option to circumvent that.
Only way I was able to fix it is to copy-paste the underlying code of GetMousePointerEventData, ProcessMove, and ProcessDrag into that custom FirstPersonInputModule (instead of just calling the base methods), then removing the code that disables functionality when Cursor.lockState == CursorLockMode.Locked.
It’s not really an advisable thing to do, since it makes the FirstPersonInputModule potentially become incompatible if a version update of Unity UI ever comes that changes the code inside PointerInputModule.
Sorry for digging this out but I came across this script and found that it makes cursor show and hide constantly and also influence the movement smoothness. Solution is to change CursorLockMode.None to CursorLockMode.Confined
IPointerHandler behaviour is problematic when you’re locking your cursor because it by default always put the cursor outside the screen. With the new input system and …? version you can fix that.