Search Unity

TextMesh Pro Clickable text link example doesn't work

Discussion in 'UGUI & TextMesh Pro' started by vincent-savysoda, Apr 2, 2019.

  1. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    33
    Hi, I just loaded up the TextMeshPro package, and was trying to see how the "clickable text" worked in Example scenes 12 and 12a, but to my surprise none of them work properly. In Example scene 12, the hover event works but not the clicks, and 12a doesn't work altogether. I'm currently using Unity version 2018.3.10f. Is anyone having a similar problem?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    These two examples were only designed to handle / respond to hovering over text elements.

    If you take a look at the TMP_TextEventHandler.cs script used in Example 12a, you will see that in LateUpdate() it simply first checks if the mouse position interests with the RectTransform and if so, potentially interesting with characters, words, line, links, etc. Results are output in the Console.

    To add support for Click, you would end up using the same utility functions from this example where instead of just checking for hovering, you could implement your own click tracking (recommended) or use OnPointerClick which would require adding a 2D Raycaster on the Camera and then Box collider on the text object.

    EDIT
    To quickly add support for click, simply replace line 125 of the TMP_TextEventHandler.cs as follows:
    Code (csharp):
    1. if (Input.GetKeyDown(KeyCode.Mouse0) && TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
    This will make all interactions respond to mouse click.

    Note that since that was initially designed for hover where I didn't want to fill the output console while hovering over the same portion of text, it ignores subsequent hover / clicks on the same portion of the text.
     
    Last edited: Apr 2, 2019
    yyylny likes this.