- Home /
How to detect if a gameobject collides with a image on a worldspace canvas
If I have a quad in 3d, with a canvas on it, with a image, how can I detect if a object, say a missile collides with the image on the worldspace canvas? Note the mouse and screen are not involved in this, there is no 'clicking' only a missile heading to a quad with a canvas image on it in worldspace. Thanks!
Answer by Zaeran · Dec 30, 2020 at 03:21 AM
You should still be able to add a regular box collider to the canvas, or at least to a transparent image that's taking up the full area of the canvas.
There are possibly dozens of images on the canvas, moving about, which I need to detect which the missile hits. I've considered adding a mesh collider to the object, then getting the UV coordinate of the hit, and then Lerping 0-1 to the x,y positions of the images to try to find the hit...
It just seems Unity must have some way to detect UI collisions with gameobjects
Answer by MSavioti · Dec 30, 2020 at 03:37 AM
As long as the image attached to it is marked as raycast target, you can detect it with raycasting.
The images are set as raycast target, however Physics.Raycast does not return a hit against it, is there another type of raycast which needs to be done?
Physics will work only if you put a collider on it. To detect UI elements you have to use GraphicRaycaster.
Your answer
![](https://koobas.hobune.stream/wayback/20220613022351im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
World space buttons and preventing UI touch passthrough 0 Answers
Unusual trouble with OnPointerClick 1 Answer
Canvas in World Space 1 Answer
Dragging panel(prefab) from screen space canvas to world space canvas and scaling to fit 0 Answers
Worldspace canvas blocking input of Screen Space Overlay Canvas 0 Answers