If the function should be called for
every subtitle, you can hook up your function to the typewriter effect's OnEnd() UnityEvent.
Otherwise, it's easy to coordinate the typewriter effect and sequences. For example:
If you can make your code into a
custom sequencer command instead of registering it as a Lua function, you can do this:
Coordinating the typewriter effect and Script field is more complicated. The Script field runs just before the subtitle starts. The idea is that Lua is primarily for internal data management (e.g., setting variables), whereas sequences are for user experience activity that depend on timing, such as typewriter effects, animation, and audio.
If you can't use a custom sequencer command, you could get your Lua registered function to hook into the typewriter's OnEnd() event in code. Example:
Code: Select all
void Awake() // Register Lua function.
{
Lua.RegisterFunction("MyFunction", this, SymbolExtensions.GetMethodInfo(() => MyFunction()));
}
void MyFunction()
{
var typewriter = // (Get a reference to the appropriate typewriter effect)
typewriter.onEnd.AddListener(() => { Typed(typewriter); });
}
void Typed(AbstractTypewriterEffect typewriter)
{
typewriter.onEnd.RemoveListener(Typed);
// Do your thing here.
}