Search Unity

How to make Text with interactable 'parts'.

Discussion in 'UGUI & TextMesh Pro' started by kscho, Mar 16, 2017.

  1. kscho

    kscho

    Joined:
    Jun 17, 2014
    Posts:
    59
    I would like to show naturally wrapped text with interactable components in a text UI box.

    For example, I want to display 'There are apples and oranges in a basket on the table. They glisten in unison in a pool of moonlight.' If the players click on the 'apples' or the 'oranges' word, an event is triggered. If the player click other words, nothing happen.

    How can I achieve this with Unity Text UI?
     
    Last edited: Mar 16, 2017
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    With TextMesh Pro (which is now for free and will be included in the next version of Unity) you can create links inline in a text AFAIK.
    Not sure if you can connect custom logic to such a link or something similar.

    However, with the normal Text component of Unity UI it is not possible.
     
    kscho likes this.
  3. kscho

    kscho

    Joined:
    Jun 17, 2014
    Posts:
    59
    thank you, hosnkobf ... that's depressing. Link is not enough for my design.

    I'm planning a novel gamebook to follow up on my hit game, Hyper Rift. I want the player to be able to ... say .. drag the 'knife' on the table to the 'apple' in the basket and trigger an event. I guess none of that would be possible, even with text mesh pro.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    TextMesh Pro does provide for the ability to detect interactions with characters, words, lines and links. The example scene "Text Interactions" is an example of how events can be triggered and handled when the cursor is over a character, word or link.

    Just take a look at the Event Handler and script used in that example scene which provides a good example of how you could implement your own custom logic based on interactions with any of those text elements.
     
  5. kscho

    kscho

    Joined:
    Jun 17, 2014
    Posts:
    59
    hi stephan, where is this 'Text Interactions' example?
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Look at example 12a in "TextMesh Pro/Examples/Scenes/..."
     
    kscho likes this.