Align TextMesh Pro with Normal

Hi! Can someone help me with this rotation?
I want to align it with the raycast hit.normal rotation…

This is my code:

using UnityEngine;
using System.Collections;


namespace TMPro.Examples
{

    public class AlignText: MonoBehaviour
    {

        public float AngleMultiplier = 1.0f;
        public float SpeedMultiplier = 1.0f;
        public float CurveScale = 1.0f;

        private TMP_Text m_TextComponent;
        private bool hasTextChanged;

        private struct VertexAnim
        {
            public float angleRange;
            public float angle;
            public float speed;
        }

        void Awake()
        {
            m_TextComponent = GetComponent<TMP_Text>();
        }

        void OnEnable()
        {
            TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
        }

        void OnDisable()
        {
            TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
        }


        void Start()
        {
            StartCoroutine(AnimateVertexColors());
        }


        void ON_TEXT_CHANGED(Object obj)
        {
            if (obj == m_TextComponent)
                hasTextChanged = true;
        }

        IEnumerator AnimateVertexColors()
        {
            m_TextComponent.ForceMeshUpdate();

            TMP_TextInfo textInfo = m_TextComponent.textInfo;

            Matrix4x4 matrix;

            int loopCount = 0;
            hasTextChanged = true;

            VertexAnim[] vertexAnim = new VertexAnim[1024];
            for (int i = 0; i < 1024; i++)
            {
                vertexAnim[i].angleRange = Random.Range(10f, 25f);
                vertexAnim[i].speed = Random.Range(1f, 3f);
            }

            TMP_MeshInfo[] cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
                int characterCount = textInfo.characterCount;

                if (characterCount == 0)
                {
                    yield return new WaitForSeconds(0.25f);
                }


                for (int i = 0; i < characterCount; i++)
                {
                    TMP_CharacterInfo charInfo = textInfo.characterInfo[i];

                    if (!charInfo.isVisible)
                        continue;

                    VertexAnim vertAnim = vertexAnim[i];
                    int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
                    int vertexIndex = textInfo.characterInfo[i].vertexIndex;
                    Vector3[] sourceVertices = cachedMeshInfo[materialIndex].vertices;
                    Vector2 charMidBasline = (sourceVertices[vertexIndex + 0] + sourceVertices[vertexIndex + 2]) / 2;
                    Vector3 offset = charMidBasline;

                    Vector3[] destinationVertices = textInfo.meshInfo[materialIndex].vertices;

                    RaycastHit hit;

                    if (Physics.Raycast(offset, Vector3.forward, out hit))
                        Debug.DrawLine(offset, hit.point, Color.green, 10.0f, false);
                float offs = -7.5f;

                    destinationVertices[vertexIndex + 0].z = hit.point.z + offs;
                    destinationVertices[vertexIndex + 1].z = hit.point.z + offs;
                    destinationVertices[vertexIndex + 2].z = hit.point.z + offs;
                    destinationVertices[vertexIndex + 3].z = hit.point.z + offs;


            }
                for (int i = 0; i < textInfo.meshInfo.Length; i++)
                {
                    textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
                    m_TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
                }
                loopCount += 1;
                yield return new WaitForSeconds(0.1f);
            }
   

    }
}

Someone?

Wait… are you rotating your meshes by changing the vertices?

Why not just set the rotation portion of the Transform instead. And not bother touching the vertices?

Then you can just use something like Quaternion.LookRotation to pick a vector looking in the direction of the normal:

Sorry…but I need to do it with Text Mesh component or with TextMesh Pro… can I manipulate transform for each letters?

Can someone tell me if it’s possible to do that?

I haven’t tried what you are trying, but there is a UI subforum that also includes Textmesh pro Unity Engine - Unity Discussions so you might have better luck asking there.