textmeshpro font size change problem in menus

Hello everyone,

I would like to navigate through the menus like this:

the normal color (in the selectable component) is gray, the select color white and the pressed color yellow,

apart from changing color I would like the size of the font textmeshpro to be equal to 28 constant when it is gray, yellow is equal to 40 constant, and if the color is white that means selected the font size text mesh pro varies progressively between 28 and 40 according to a given speed,

I tried this code and changed the textmeshpro font setting to dynamic and it didn’t work:

1-not gradual size change font textmesh pro but abrupt

2-all the texts of the menus change at the same time whether it is in 28 or 40 suddenly whatever their colors white or gray gold I would like only the text in white to change gradually.

Please help me please, thank you very much.

here is my code:

using UnityEngine;
using TMPro;

public class Selectionne : MonoBehaviour
{
    Color gray = new Color(0.5f, 0.5f, 0.5f), white = new Color(1f, 1f, 1f), yellow = new Color(1f, 1f, 0.5f);
    Color bouton;
    TextMeshProUGUI texte;
    bool tour1 = true;
    public float speed;
    float totalSpeed;

    // Start is called before the first frame update
    void Start()
    {
        bouton = GetComponent<TextMeshProUGUI>().color;
        texte = GetComponent<TextMeshProUGUI>();
    }

    // Update is called once per frame
    void Update()
    {     
        if (bouton ==white)
        {
            if (tour1)
            {
                 if (texte.fontSize < 40)
                {
                    totalSpeed+= speed * Time.deltaTime;
                    texte.fontSize += (int)totalSpeed;
                }
                else
                {
                    tour1 = false;
                    totalSpeed= 0;
                }
            }
            else
            {
               if (texte.fontSize > 28)
                {
                    totalSpeed+= speed * Time.deltaTime;

                    texte.fontSize -= (int)totalSpeed;
                }
                else
                {
                    tour1 = true;
                    totalSpeed = 0;
                }
            }
        }
        else if (bouton == gray)
            texte.fontSize = 28;
        else if (bouton == yellow)
            texte.fontSize = 40;
    }
}

Cordially .

In your button component, change trannsition to “animation”. Then, click “Auto Generate Animations” and save the animator in your assets. open the animation window while the button is selected in the inspector. In the animation window, at the top, you will see a drop down list with all the button states. Choose normal from the list. Then, press the record button near the drop down (It’s a red circle). While recording, change the button’s color to gray and set the text size to 28. Press the record button again to stop recording. Now your button will be gray when not pressed. After that, In the drop down list, change from “normal” to “pressed”. Press record, Change the button’s color to yellow and the text size to 40. Stop recording. In the drop down list, Change from “pressed” to “selected”.Start recording. Set the button’s color to white and the text size to 28. Now, While still recording, drag the white line on the big wide box on the right side of the animator, drag it from it’s upper side, where it shows “0:00, 0:01, 0:02…”. Drag it to where it shows a particular number of seconds. This number would be the time that takes the text to become big again. So, for instance, if You choose “0:07” It will take the text 7 seconds to grow big again. After dragging the white line to there, change the text’s size to 40. Now, while still recording, drag the line again to twice from what is was before.So, If you dragged it to “0:07”, drag it to “0:14”. Set the text’s size to 28. Stop recording. Now it shold work when you run the game. If you dont want the transitions between gray, yellow and white to be smooth, open the “button” animator in the assets. the “button” animator is located where you saved it in the beginning, when you clicked “Auto Generate Animations”. In the opened animator window, click on the white arrow going from “Any state” to “pressed”, in the inspector click on “settings” and set transition duration to 0. Repeat for selected.
To change the speed of the text when the button is white, click on the “Selected” rechangle is the animator window. The speed variable there will controll the speed of the text.
No coding solution, I hope it will work for you, It works for me. The site won’t let me upload pictures so I can’t show screenshots.
**If the component is not a button, read the comment