Subtitles sound like they’ll be pretty boring, given the current Unity toolset, but I haven’t tried it yet, and I definitely want them for my next game. (I always watch movies with subtitles on, even though, generally, both spoken and typed dialogue is in English - it helps me comprehend the material faster, never having to rewind.) Anybody have a good, fast, clean solution to getting the written words to line up in time with what’s being spoken, and the relevant animations?
How about using animation events to change the subtitle text and play the relevant speech audio. You could wrap it all into a function with an indexed array containing the sequential text and audio.
Ask Jashan how he did his text dialogue for Traces of Illumination. His is a very impressive approach to a subtitle system.
I just had a script with an array of strings and a function that displayed the text at the position sent to the function. If you give it a large enough box, set it to wrap, and set it to upper center, it’ll display anything without too much trouble.
Of course, you’ll have to call it based on the timing of your event, but that’s usually tied to function calls anyway.
var myStrings : String[];
var curString : int = 0;
var displaying : boolean = false;
var myStyle : GUIStyle;
function ShowMe(hit : int)
{
curString = hit;
displaying = true;
yield WaitForSeconds((myStrings[curString].length / 20) + 1);
displaying = false;
}
function OnGUI()
{
if (displaying) {
GUI.Label(Rect(20, Screen.height - 80, Screen.width - 40, 60), myStrings[curString], myStyle);
}
}
Heh it would be an interesting project to create an editor script to parse standard subtitle files, add them in and set up animation events as needed
Though this script has really helped me no end, how do I add to the Array in a start function as opposed to editing it all in the Inspector?
I’m doing purely subtitles for my game and I wanted to see how people did it. I didn’t really like the codes being used here so I made my own. I have a single C# script with a function to show given text in a specific place for a certain time. Code seen below…
using UnityEngine;
using System.Collections;
public class ShowText : MonoBehaviour {
//Stores text so it can be output within the OnGUI function.
private string say;
//When true, text is displayed each frame, when off it iss't displayed
private bool displaying;
//This text style can can be easily changed in the inspector
public GUIStyle myStyle;
//This function can be called from other scripts. You must provide the text, the starting positions
//and the time the text will last.
public void DisplayTextHereFor (string text, float distFromLeft, float distFromBottom, float time) {
say = text;
displaying = true;
Invoke ("StopDisplaying", time);
}
//Draws the text on the GUI while "displaying" is true
void OnGUI() {
if (displaying) {
GUI.Label(new Rect(10, Screen.height - 100, 0, 0), say, myStyle);
}
}
//Simply says to stop displaying
void StopDisplaying () {
displaying = false;
}
}
If I want to utilise this function from another script then I can do so like this:
public class OpeningSequence : MonoBehaviour {
//Name this variable "ShowText" then drag the "ShowText" script into the variable through the inspector.
public ShowText textDisplayingScript;
void Start () {
//Shows two lines of text at the bottom left of the screen (10 pixels from the left and 50 from the bottom).
//The text lasts for 5 seconds before it disappears.
textDisplayingScript.DisplayTextHereFor ("A long time ago, a very strange thing happened. \n" +
"A violet moon appeared in our sky...", 10, 50, 5);
}
}
I don’t know if people will prefer this to the other codes but it works for me ^^