Find gameobjects in a crosshair?

Hi, I have a gameobject attached 3 units in front of my plane. I convert the wolrd space to a gui rect and then I draw the gui. I’m trying to figure out how to check if there’s an enemy within the crosshair rect. I have tried with RaycastHit, but since the gui is not always in the center of the screen, that’s very difficult.

alt text

What would be the best way to see what gameobject is within the gui rect?

This returns a ray going from camera through a screen point.

You can use this in a RayCast, check the last example in the RayCast Unity Scripting Reference : Unity - Scripting API: Physics.Raycast