How can i lock my raycast (cursor) to the middle of the screen.

void Update()
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = true;


My code So far:

The raycast should be fired from the MainCamera.forward direction. You can check the ray by doing a debug.drawline(camera.transform.position, camera.forward) in the update and the ray will always hit the middle of the screen.