Hey all,
I’m very new to code so please forgive my noobish ways. I’m trying to write a simple code that reveals the next letter in a paragraph of text with Input.anyKeyDown. Basically I want it to show one letter at a time no matter the key you press.
While searching for an answer I came across an AutoType script. With many failed attempts to edit it for my needs I decided to come here to ask for help.
using UnityEngine;
using System.Collections;
public class TextAuto : MonoBehaviour
{
public float letterPause = 0.05f; //NOT NEEDED
public GUIStyle font;
string message;
string text;
void Start (){
message = "Welcome new warrior! This is a blue screen, you must fight your way out! " +
"Without any hands or other parts. This may take some time...";
text = "";
//StartCoroutine(TypeText());
}
IEnumerator TypeText (){
foreach (char letter in message.ToCharArray())
{
text += letter;
yield return 0;
yield return new WaitForSeconds (letterPause);
}
}
void OnGUI(){
GUI.Label(new Rect(0, 0, 256, 1024), text, font);
}
void Update(){
if(Input.GetKeyDown (KeyCode.Return)){
StopAllCoroutines();
text = message;
}
}
}
Cheers
Adam