unity Raycasting from center of screen instead of mouse location code example
Example: raycast from center
Transform cam = Camera.main.gameObject.transform;
Ray ray = new Ray(cam.position, cam.forward);
Transform cam = Camera.main.gameObject.transform;
Ray ray = new Ray(cam.position, cam.forward);