Raycast based on a Rect?

Hello,

First I used Input.MousePosition to to select objects using raycasts. This works fine. However, now I have a crosshair which I render with a Texture2D, and I want the crosshair to be the origin of the raycast, like I previously did with Input.MousePosition.

How do I do this?

EDIT:

Heres what I use

if (UseMouse)
	ray = Camera.main.ScreenPointToRay(Input.mousePosition);
else
	ray = Camera.main.ScreenPointToRay(new Vector3(Position.x + Position.width / 2, Position.y + Position.height / 2,0));

Fixed screen coords:

If you have the rect that renders the crosshair, you can get the centre of it using

Vector2(rect.x + rect.width / 2, rect.y + rect.height / 2);

If you want to use this value in raycasting, you'll have to modify some things. ScreenPointToRay uses screen coordinates- these go from the bottom left to the top right as opposed to GUI coordinates, which go from top left to bottom right. I have no idea why they decided it would be a good idea to have inconsistencies like that, but there you go.

fixedScreenCoord = Vector2(rect.x + rect.width / 2, Screen.height - (rect.y + rect.height / 2));