A system for displaying text in Unity like in old RPG games.
- Add TextHandler prefab to your scene.
- Or, create a new object and attach the TextHandler script, and a AudioSource in the inspector
- Link the "Text Box" field in the TextHandler script to a textbox in the scene
- In another script/object, or internally within TextHandler, create a new Voice(). Voice() takes 4 parameters for its constructor: 1. float rate: How time, in seconds, between each character reveal 2. float low: The pitch of the lowest possible note (Expressed as a pitch coefficient) 3. float high: The pitch of the highest possible note 4. AudioClip sound: A reference to a AudioClip to be played when revealing notes. (See Unity documentation)
- Link the Voice to TextHandler using TextHandler.SetVoice(Voice v) For example: GetComponent().SetVoice(new Voice(0.1f, 1, 5, sound));
- Give TextHandler an array of strings to display using TextHandler.SetText(string[] newText)
- Now, call TextHandler.AdvanceLine() to start advancing lines. (By default, this is set to OnMouseUp)
Included is a Example.unity scene is included to show how to properly load TextHandler and use it. Within TextHandler.cs, Void Start(), uncomment these lines to try it out:
AudioClip sound = Resources.Load("bleep") as AudioClip;
Voice v = new Voice(0.1f, 1, 3, sound);
string [] examples = {"Hello world!", "Test text!"};
SetVoice(v);
SetText(examples);
CC0