Can't interact with world space ui button when cursor mode is locked any solutions?

Can’t interact with world space buttons when cursor is locked (can’t interact as in button doesn’t fade to a colour when hovering over) any other way to lock cursor to centre and also interact with world space buttons?

Hello. This script should work.

public class LockMouse : MonoBehaviour
{
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    public static extern bool SetCursorPos(int x, int y);

    public bool isLock = true;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            isLock = !isLock;
        }

        /*
            In the editor, the cursor will be slightly offset from the center,
            but in the build it should be exactly in the center (if the game is full screen)
        */

        if (isLock)
        {
            SetCursorPos(Screen.width / 2, Screen.height / 2); 
            Cursor.visible = false;
        }
        else
        {
            Cursor.visible = true;
        }
    }
}

Is there any way to make it such that it is position in the middle as i have a crosshair in the middle which i wish to configure for user interface @DenisIsDenis