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.
  2. Dismiss Notice

Question Color in a text issue

Discussion in 'Scripting' started by Sylon87, Sep 24, 2020.

  1. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196
    hello!
    i hope someone can help me.
    i have a like typewriter effect on my UI and on my text sometimes there is also a color tag, i'm actually checking for the "<" char to detect from where start but doesn't catch it, ii need to print it at one time, right now it will display the entire code untill is completed... any help?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    I just got done solving this exact problem in my own project. I'll share my solution with you :)

    https://pastebin.com/bHWdtDiQ

    How to use:

    You need a TextMeshPro text object assigned. (TextMeshPro or TextMeshProUGUI). If you want to use normal UI Text, it should be pretty trivial to swap it out in the code.
    Set the TextToDisplay property either from the inspector or through code.
    Then call the Play() method to start displaying text.
    You can set the speed with the "characterRate" field.
    It works with Rich Text tags.
     
    Last edited: Sep 24, 2020
  3. Sylon87

    Sylon87

    Joined:
    Aug 20, 2018
    Posts:
    196
    hello! thank's you for your reply.
    actually i did a similar things but on the
    nextChar == TAG_OPEN is not going to catch any '<' and when i try to debug with the log will display '<' as " "
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    Here was my attempt from earlier this year. See attached package.

    You can enter the text into the field in the script, OR it will work on text already emplaced in a UI.Text object.

    It would be easy to convert to TMPro, go nuts.
     

    Attached Files: