Search Unity

TextMeshPro: Can't change the color of single character.

Discussion in 'UGUI & TextMesh Pro' started by fsemblert, Aug 13, 2018.

  1. fsemblert

    fsemblert

    Joined:
    Oct 14, 2016
    Posts:
    13
    In my game, I have a world space TMP with the initial color set to black, when the user click/touches a character of the text, it should change to yellow. Am following several video examples and forum posts, on how to do this, but all of them are for GUI text and I need this functionality for a world space text.

    Code (CSharp):
    1. int i = TMPro_textUtilities.FindIntersectingChararcter(myTMP, Input.mousePosition, Camera.main, false);
    2. myTMP.textInfo.characterInfo[i].vertex_BL.color = myColor;
    3. myTMP.textInfo.characterInfo[i].vertex_BR.color = myColor;
    4. myTMP.textInfo.characterInfo[i].vertex_TL.color = myColor;
    5. myTMP.textInfo.characterInfo[i].vertex_TR.color = myColor;
    and

    Code (CSharp):
    1. myTMP.textInfo.characterInfo[i].color = myColor;
    Has no effect, regardless of render mode or forcing the TMP to update.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The TMP_TextInfo contains data about the generated text object. This information can be used to modify parts of the text object but the TMP_TextInfo itself doesn't affect the text object. Think of it as an output and not input.

    To learn how to use the TMP_TextInfo to modify things like character or word colors or even position of vertices, take a look at example 23 - Animating Vertex Attributes and the scripts used in that example.