# Writing Custom Actions C\#

> *You're reading the documentation of an older/legacy version, Text Animator 1.X.  To read the latest version, please visit this page instead* [2.X (EN)](https://docs.febucci.com/text-animator-unity/2.x/)*. How to update:* [Upgrading from 1.X to 2.X](/text-animator-unity/2.x/other/changelog/upgrading-from-1.x-to-2.x.md)

***

You can create your own Custom Actions via script (C#).

(Do not forget to read here: [Performing Actions While Typing](/text-animator-unity/1.x/typewriter/performing-actions-while-typing.md) )

***

## How to create custom actions

### 1. Registering custom action IDs

In order to tell TextAnimator which tags are custom actions, you need to add them in the "Custom Actions" array (located in the TextAnimator's `GlobalData Scriptable Object` asset).

*P.S. In case you don't have a GlobalData Scriptable Object, please* [*read here*](/text-animator-unity/1.x/effects/creating-effects-in-the-inspector.md#global-effects) *on how to create it.*

In this example, I'm setting "playAudio" as a custom action.

### 2. Processing actions in a custom typewriter

Your Custom Actions can be performed by a custom typewriter:

1. Create a new typewriter class (Read more here).
2. Override the `DoCustomAction` method *(do not invoke the base method)*.
3. Perform specific actions based on the given "`actionID`" and use any `parameter` as you wish.
4. Add your new custom typewriter near a TextAnimator component, instead of the default "TextAnimatorPlayer".

#### Example script

```csharp
using System.Collections;

//custom typewriter class
public class CustomTAnimPlayer : Febucci.UI.TextAnimatorPlayer
{
    protected override IEnumerator DoCustomAction(Febucci.UI.TypewriterAction action)
    {
        switch (action.actionID)
        {
            case "playAudio": //example: an action that plays given sounds
                for(int i = 0; i < action.parameters.Count; i++)
                {
                    AudioManager.PlaySoundFromID(action.parameters[i]);
                }
                yield return new WaitForSeconds(2); //holds the typewriter for 2 seconds
                break;
        }

    }
}
```

Done! With this simple procedure, you can add any Custom Action you want.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.febucci.com/text-animator-unity/1.x/extra-customization/writing-custom-actions-c.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
