AutoType

From Unify Community Wiki
Revision as of 20:52, 10 January 2012 by NCarter (Talk | contribs)

Jump to: navigation, search

Author: Daniel

Contents

Description

Automatically types a string of text typewriter style.

Usage

Place this script onto a GUIText. The text in the GUIText object's Text field will be used.

Javascript - AutoType.js

var letterPause = 0.2;
var sound : AudioClip;
 
private var word;
 
function Start () {
	word = guiText.text;
	guiText.text = "";
	TypeText ();
}
 
function TypeText () {
	for (var letter in word.ToCharArray()) {
		guiText.text += letter;
		if (sound)
			audio.PlayOneShot (sound);
		yield WaitForSeconds (letterPause);
	}		
}

C# - AutoType.cs

Conversion: paste120

using UnityEngine;
using System.Collections;
 
public class AutoType : MonoBehaviour {
 
	public float letterPause = 0.2f;
	public AudioClip sound;
 
	string message;
 
	// Use this for initialization
	void Start () {
		message = guiText.text;
		guiText.text = "";
		StartCoroutine(TypeText ());
	}
 
	IEnumerator TypeText () {
		foreach (char letter in message.ToCharArray()) {
			guiText.text += letter;
			if (sound)
				audio.PlayOneShot (sound);
				yield return 0;
			yield return new WaitForSeconds (letterPause);
		}      
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox