Search Unity

How change TMP UGUI GLOW color using a script

Discussion in 'UGUI & TextMesh Pro' started by Argument, Jan 3, 2020.

  1. Argument

    Argument

    Joined:
    Jul 5, 2015
    Posts:
    20
    Hello.

    Help plz. How change in Text Mesh Pro UGUI -> Glow -> color using a script?


    Thnx.
     
    filip-mixedworld likes this.
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Since those properties are in reality material properties, you can already access those by using the Unity API for materials. So for instance, if you wanted to change glow power, you would do something like this.

    Code (csharp):
    1.  
    2. m_TextMeshPro.fontSharedMaterial.SetFloat("_GlowPower", 0.5f);
    3. // Instead of using a string to access the material property, you could use the ShaderUtilities class I provide
    4. m_TextMeshPro.fontSharedMaterial.SetFloat(ShaderUtilities.ID_GlowPower, 0.5f);
    5. // Since some of the material properties can affect the mesh (size) you would need to update the padding values.
    6. m_TextMeshPro.UpdateMeshPadding();
    7.  
    Now some of the Material properties are using Shader Features or Keywords which have to be enabled. Underlay and Glow for instance use Shader features and have to be enabled.
    Code (csharp):
    1.  
    2. // Assuming m_sharedMaterial contains a reference to the material you are using.
    3. m_sharedMaterial.EnableKeyword("UNDERLAY_ON");
    4. m_shaderMaterial.DisableKeyword("UNDERLAY_INNER");
    5.  
    All the shader properties can be seen when selecting the shader or opening the shader in Mono or Visual Studio.
     
    Mauri and Argument like this.
  3. Argument

    Argument

    Joined:
    Jul 5, 2015
    Posts:
    20
    Many thanks.
    My code:
    Code (CSharp):
    1. m_TextMeshPro.fontSharedMaterial.SetColor(ShaderUtilities.ID_GlowColor, new Color32(255, 240, 0, 100));
     
    Benfont likes this.
  4. Benfont

    Benfont

    Joined:
    Nov 11, 2017
    Posts:
    21
    Thanks!!!