Easy Subtitles System


Subtitles displays nice-looking subtitles and closed captions for your game with smooth animations and fade in/out effects.


Show subtitles with a single line of code

After importing the package, add the Subtitles.cs script anywhere in your scene (the most common place is on your main camera). Set the GUI Skin parameter in the inspector (you can use the default one in the Scripts/ folder of the addon. You can now show a simple subtitle with one of these functions:

Subtitles.show(string message, float duration (in seconds), Color c);
Subtitles.show(string message, float duration (in seconds), Color c, bool italic);

Show subtitles with XML

You can also load subtitles from an XML file like this:

<?xml version="1.0"?>
                <style id="npc" red="0.25" green="0.5" blue="1.0" italic="1" />
                <style id="hero" red="1.0" green="1.0" blue="1.0" italic="1" />
                <style id="ambient_sounds" red="0" green="1.0" blue="1.0" italic="0" />
                <subtitle id="npc_guard_spotted" duration="2.5" style="npc">Freeze!</subtitle>
                <subtitle id="hero_spotted_response" duration="3.5" style="hero">I don't think so.</subtitle>

The top part is the <styles> section. You define a style with an id, a color (red, green and blue) and if its in italic or not. Then comes the <texts>/<subtitle> part, where the "style" attributes must be a style id defined in the precedent <styles> section.

You can load the XML file with the function Subtitles.loadFromXML(string file):

Subtitles.loadFromXML("Subtitles"); // Subtitles.xml must be in a "Resources" folder
Subtitles.loadFromXML("Subtitles/english"); // english.xml must be in a "Resources/Subtitles" folder

You can also give a TextAsset objet to the function instead of a string:

Subtitles.loadFromXML(TextAsset xmlfile);

You can then show a subtitle by its ID with Subtitles.showByID(string id):


See the demo scene for a complete example.



Fade In Time
Duration of the fade in effect when subtitle appears (in seconds).
Fade Out Time
Duration of the fade out effect when subtitle disappears (in seconds).
Line Spacing
Here you can add an extra line spacing. Can be negative.
Margin Percent
Left and right margin, in % of the screen width
Position Y
Y position of the most recent subtitle, in % of screen height
Box Draw
Should it draw a box around subtitles?
Box Margins
Inner margins of the box.
GUI Skin
The GUI Skin to use for Subtitles

Subtitles Editor

You can also edit your XML Subtitles files with the new Subtitles Editor. You can access the editor in the Window menu:

When you first open the editor window, only two buttons are available : New file... and Open file..., they are pretty straightforward. Click on New file... and create somewhere in your project the XML Subtitles file.

Save will save the file, + Add a style and + Add a subtitle will add a style and a subtitle. In the main part of the window are the style on the top and the subtitles on the bottom. For each style row you can:

For each subtitle row you can: Moreover, some buttons on the left are for styles and subtitles: Don't forget to save your file before closing the Editor!

Other examples

Subtitles.show("Hello there", 5.5f, Color.blue, true);
Subtitles.show("How are you?", 2.5f, Color(0.5f, 0.5f, 0.5f, 1f));
Subtitles.getMessageByID("subtitle_id"); // Returns the text associated with the specified id

You now know everything about this addon!