I’ve got a regular TextMeshPro text GO (stand-alone, without canvas) and want to write to console when someone clicks on it. I already added a “ClickText” script to the GO but can’t get any of the functions to trigger. What I’ve tried so far:
Implement “IPointerClickHandler” in “ClickText”, with “OnPointerClick(PointerEventData eventData)” - didn’t work.
Add a “PointerClicker” event trigger for the GO (through the editor) and set it to call “ClickText.onClick()” function - didn’t work.
“OnMouseDown” - didn’t work (only meant for GameObjects with an actual collider afaik)
How do you register clicks on a TMP text (in Unity 2021.1.6f1)?
I added a MeshCollider and ticked “Is Trigger” and now “OnMouseDown” is called but the other two versions (IPointerClickHandler & Event) still don’t work. Any guesses why?
This is an old post, but someone else might have this issue, so…
I don’t think the GO has a mesh or any inherent interactable component, so even though you add the event, it doesn’t have anything to trigger from. When I was attempting what you were, I added the event to the Text Object itself and it worked.
@Kheremos
That’s exactly what I did, please read my second post too.
I just tested the “IPointerClickHandler” version again and it still doesn’t work in my project (Unity 2021.2.13f1). Not sure if I’m missing something else but at least “OnMouseDown” has been working just fine the last 10 months.