AutoType

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by Paste120)
Line 1: Line 1:
 +
Author: Daniel
  
 +
== 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>

Revision as of 19:27, 19 October 2009

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