1. Home
  2. Docs
  3. 3D Text Effects – Quick How-Tos
  4. How To – Use a 3D text animation prefab in a scene

How To – Use a 3D text animation prefab in a scene

The following article is based on the scene in Text3D/Tutorials/Quick Text Creation.

We would often want to show text effects in response to a game event. This can be done easily by saving the text effect into a prefab and then instantiating it using script. 3D Text Effects has a method that does this for you , here is how it works :

  1. Create a new mono behavior. This behavior will trigger the text effect when you would like to show. Add the following property to the script :
    public GameObject PrefabObject;

2. Now we can show the prefab object from script using the following call :

 DynamicTextElement.ShowTextEffect(PrefabObject, showText);

this method accpets a prefab object and text string. The text string can be formatted in any way you would like. In the this tutorial , it is set to a random number of defense points:

        string TextFormat = "+{0} Defense";
        int RandomNumber = Random.Range(1, 100); // select a random number. In a real life use case,  this number can be something relevant to your game instead of a random.
        string showText = string.Format(TextFormat, RandomNumber); // format the text

3. Drag and drop the text prefab into the script object:

4. Make sure to destroy the text effect game object after you are done with it. This can be done by adding a SelfDestory comopnent to the prefab :

Run the scene. You should see the 3D text effect going.