0

I used the example provided by Unity (https://docs.unity3d.com/ScriptReference/UI.Graphic.html) to create a new visual UI component.

However, I now want to detect a click event on the newly created mesh. To do so I implemented the IPointerClickHandler interface but the click is detected when I click within the RectTransform box of the GameObject but not on the actual Mesh (which is outside of the RectTransform).

Screenshot (mesh in pink):
Screenshot (mesh in pink)

I tried the solutions suggested here for "NON-UI OBJECTS" https://stackoverflow.com/a/41392130/9989790 but with no success.

Any idea on how to do it?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Drosera
  • 1
  • 1

1 Answers1

0

You need to have a "MeshCollider" component on the object. In addition, your camera needs to have a "physics raycaster" component. The ray is cast out from the camera, and if it collides with your mesh-collider, pointer-enter/exit (and potential-click) events will be sent to your object.

But even with these required components in place, you'll still need to watch out for overlapping objects that might "steal" the mouse click.

Glurth
  • 290
  • 1
  • 17