Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question How to detect if mouse over TMP_Text sprites.

Discussion in 'UGUI & TextMesh Pro' started by Xahutek, Jan 28, 2023.

  1. Xahutek


    Feb 27, 2020
    Hey there,
    I'm trying to make a Tooltip system for a game. I already made a component I can attach together with TMP_Text that enables me to show tooltips when hovering words like this:
    Code (CSharp):
    1. //On a script attached to the TMP_Text object.
    2. public void OnPointerMove(PointerEventData eventData)
    3.     {
    4.         int wordIndex = TMP_TextUtilities.FindIntersectingWord(text, Input.mousePosition, Camera.main);
    6.         if (wordIndex != -1)
    7.         {
    8.             TMP_WordInfo wordInfo = text.textInfo.wordInfo[wordIndex];
    10.             word = wordInfo.GetWord();
    12.             //the word is used by my Tooltip system
    13.         }
    14.         else word = "";
    I would like to do the same thing for hovering over icons that are displayed as sprites in the text.
    I could not find a TMP_TextUtilities.FindIntersectingSpriteIndex(...) method or something similar that could give me any info on what if any sprite I am hovering over.

    How would I go about implementing this?
    I've been trying to get behind this for a few hours now but no answer I found seemed to lead anyhwere for me.