Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Change individual character colors through code

Discussion in 'UGUI & TextMesh Pro' started by ediit, Jan 19, 2022.

  1. ediit

    ediit

    Joined:
    Mar 17, 2018
    Posts:
    8
    Hi,
    Been looking for a few hours for how to change the color of individual TMPro text characters through code. All of the examples I've found on the forums seem to be broken. Does anyone have a way of doing this?
     
  2. Fruitfly08

    Fruitfly08

    Joined:
    Feb 5, 2021
    Posts:
    69
    what about your code isn't working? are you getting any error messages of any sort? unfortunately, your description doesn't provide much information, so it's hard to know how to help with the issues your having. According to my understanding, this is how you would change the color through code

    Code (CSharp):
    1. using TMpro; // don't forget about this, I also had a lot of issues with textmeshpro until I included this
    2.  
    3. private TextMeshProUGUI tmpObj;
    4.  
    5. tmpobj.color = new Color32(50, 50, 50, 255); // edit these values based off the colors you want
    of course, this is a very rudimentary example, so there's a lot of other things you'll need to add to get what you want to work, but hopefully this example helps!
     
  3. pihels

    pihels

    Joined:
    May 13, 2018
    Posts:
    8