AutoType

From Unify Community Wiki
Revision as of 19:27, 19 October 2009 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.

Javascript - AutoType.js

<javascript>var word = "Hello World"; var letterPause = 0.2; var sound : AudioClip;

function Start () { guiText.text = ""; TypeText (); }

function TypeText () { for (var i = 0; i < word.Length; i++) { guiText.text += word[i]; if (sound) audio.PlayOneShot (sound); yield WaitForSeconds (letterPause); } }</javascript>

C# - AutoType.cs

Conversion: paste120 <csharp> using UnityEngine; using System.Collections;

public class AutoType : MonoBehaviour {

public string word = "Hello World"; public float letterPause = 0.2f; public AudioClip sound;

// Use this for initialization void Start () { guiText.text = ""; StartCoroutine(TypeText ()); }

IEnumerator TypeText () { for (int i = 0; i < word.Length; i++) { guiText.text += word[i]; if (sound) audio.PlayOneShot (sound); yield return 0; yield return new WaitForSeconds (letterPause); } } } </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox