/RPG-Text-System

A system for displaying text in Unity like in old RPG games.

Primary LanguageC#Creative Commons Zero v1.0 UniversalCC0-1.0

RPG-Text-System

A system for displaying text in Unity like in old RPG games.

Usage

  1. Add TextHandler prefab to your scene. Screenshot 1
  2. Or, create a new object and attach the TextHandler script, and a AudioSource in the inspector Screenshot 2
  3. Link the "Text Box" field in the TextHandler script to a textbox in the scene
    Screenshot 3
  4. 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)
  5. Link the Voice to TextHandler using TextHandler.SetVoice(Voice v) For example: GetComponent().SetVoice(new Voice(0.1f, 1, 5, sound));
  6. Give TextHandler an array of strings to display using TextHandler.SetText(string[] newText)
  7. Now, call TextHandler.AdvanceLine() to start advancing lines. (By default, this is set to OnMouseUp)

Example Scene

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);

License

CC0