Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- public class Typewriter : MonoBehaviour {
- public float timeBetweenCharacters = 2;
- private Text textField;
- private string originalText;
- private int position = 0;
- private float time;
- void Start() {
- textField = GetComponent<Text>();
- originalText = ParseText(textField.text);
- textField.text = "";
- }
- string ParseText(string text) {
- string t = text;
- t = t.Replace("[device]", SystemInfo.deviceName);
- t = t.Replace("[name]", "Felix");
- return t;
- }
- void Update () {
- if(position < originalText.Length && time <= 0) {
- char c = originalText[position];
- if(c == '|') {
- textField.text = textField.text.Substring(0,textField.text.Length-1);
- } else if (c == '[') {
- textField.color = Color.red;
- } else if (c == ']') {
- textField.color = Color.white;
- } else {
- textField.text += c;
- }
- position++;
- time = timeBetweenCharacters;
- }
- if(time > 0)
- time -= Time.deltaTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement