Grow font size smoothly

I am attempting to grow my title font in a smooth manner, and I have it working correctly except that it is a little choppy. I am wanting to grow it to a size of 120 in 6 seconds. I am wondering if part of the problem is that the font size of GUIText is an int and I cannot make it a double value.

My code:

// Use this for initialization
public GUIText TitleText;

void Start () 
{
   StartCoroutine("GrowTitleFont");
}

IEnumerator GrowTitleFont()
{
    double fontsize = 0;

    for(double count = 0; count < 60; count++)
    {
       yield return new WaitForSeconds(0.10f);
       fontsize += 2;
       this.TitleText.fontSize = (int)fontsize;
    }
}

Probably choppy because as the font size changes Unity has to render the font to the new size. This rendering of the glyphs can take some time, particularly as the font size gets large.

2 Answers

2

The fact that font sizes is exactly why it’s choppy. I’m not sure if unity allows doing it the way I would. But regardless, here’s how I would do it:

First, draw it at its original size.

Next, set your Update function to constantly add Time.deltaTime to a running float number.

Then for every subsequent frame, pre-draw it on a different render target with a font size of the running number rounded down.

Then take the resulting image and scale it 1.(the decimal part of the running number)

This should cause the font to seem like its point size is smoothly increasing, but rather, it is being scaled based on a float value. But to prevent the blurriness of too much scaling, we draw it at its closest possible point number below our running number, and scale that. Makes sense, eh? If not, comment, and I’ll come up with a code example. but like I said, I don’t know if Unity allows rendering text to images.

Works for me, thanks for the input.

Any solution for this? I am stuck into same point.

3DText (AKA TextMesh) can be scaled using the regular transform scale, or characterSize (a float.)

But, they aren’t “screen” objects – they live in the world. To make it look like a GUI item, you have to use some trick like childing it to the camera or using another orthographic camera. Luckily, they are visible through everything, so you don’t have to worry about tree limbs covering them up.

Nice, didnt know about 3DText