Tanoda
ScrollingText.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class ScrollingText : MonoBehaviour
7{
8 private byte MaxLength = 12;
9 public Text label;
10 private string fullText;
11 private byte rotation = 0;
12
13 private void Start()
14 {
15 fullText = label.text;
16 if (fullText.Length <= MaxLength)
17 {
18 Destroy(this);
19 }
20 }
21
22 void Update()
23 {
24 if (Time.frameCount % 60 == 0)
25 {
26 var txt = fullText.Remove(0, rotation);
27 if (txt.Length > MaxLength)
28 {
29 txt = txt.Remove(MaxLength);
30 }
31 label.text = txt;
32 rotation++;
33 if (string.IsNullOrEmpty(label.text))
34 {
35 rotation = 0;
36 }
37 }
38 }
39}