Search Unity

Question Any way to detects inline Sprites to get sprite name/index While hovering on an inline sprite?

Discussion in 'UGUI & TextMesh Pro' started by daniel8881, Jan 10, 2023.

  1. daniel8881

    daniel8881

    Joined:
    Oct 22, 2021
    Posts:
    1
    I know there's a way to detect text by using TextUtilities something like the following snippets:

    Code (CSharp):
    1. string hoveredWord;
    2. int wordIndex = TMP_TextUtilities.FindIntersectingWord(description, Input.mousePosition, null);
    3.  
    4.         if (wordIndex != -1)
    5.         {
    6.             hoveredWord = description.textInfo.wordInfo[wordIndex].GetWord();
    7.             Debug.Log("hover on " + hoveredWord);
    8.         }
    However, it can only print out words, it prints out Nothing on inline sprites while hovering on an inline sprite. I've also tried use TMP_SpriteAsset, but it doesn't seem there's a similar method as TextUtilities.

    I'd like to do a similar effect like the video has shown :

    At 0:37, the textbox/tooltip is triggered while the mouse is hovering on the inline sprite.

    My question is, is there any ways to GET any info of inline sprites especially sprite name or sprite index while hovering on an inline sprite? Thank you!