AutoType

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
Line 27: Line 27:
 
yield WaitForSeconds (letterPause);
 
yield WaitForSeconds (letterPause);
 
}
 
}
}</javascript>
+
}</syntaxhighlight>
  
 
== C# - AutoType.cs ==
 
== C# - AutoType.cs ==

Revision as of 20:52, 10 January 2012

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