Raycast on GUI Image that is a Target Texture for a Camera

Hi all,

My English is not the best but I will try my best to explain my following problem. I have a GUI Image that acts like a monitor for a camera. Therefore that camera’s target texture is the same texture as the Image. I am doing a drag and drop feature and when I drag to the image, I want to drop that object I am grabbing where I am pointing from the camera position.

I know how to implement the dragging part but I need to know how to get the coordinate of where I am pointing from that camera when I am hovering my mouse on the image. I was playing with Raycast but you cannot do that with the GUI (as far as I know). I was playing a bit with RectTransform and getting the coordinated where I look but that sounds too complicated or not efficient. Any help appreciated.

Tricky.

You can do raycasts against UI items; see GraphicRaycaster. But it’s a little different, and the RaycastResult you get back does not contain the information you really need, such as the UV position hit.

I think you’ll probably need to roll your own solution, using the screen position of the mouse to calculate where in the target texture that would be.