cool title screen
This commit is contained in:
parent
b0625ae834
commit
949135cecb
33 changed files with 4977 additions and 7 deletions
86
Assets/Scripts/TypeWriterUI.cs
Normal file
86
Assets/Scripts/TypeWriterUI.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class TypeWriterUI : MonoBehaviour
|
||||
{
|
||||
Text _text;
|
||||
TMP_Text _tmpProText;
|
||||
string writer;
|
||||
|
||||
[SerializeField] float delayBeforeStart = 0f;
|
||||
[SerializeField] float timeBtwChars = 0.1f;
|
||||
[SerializeField] string leadingChar = "";
|
||||
[SerializeField] bool leadingCharBeforeDelay = false;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
_text = GetComponent<Text>()!;
|
||||
_tmpProText = GetComponent<TMP_Text>()!;
|
||||
|
||||
if(_text != null)
|
||||
{
|
||||
writer = _text.text;
|
||||
_text.text = "";
|
||||
|
||||
StartCoroutine("TypeWriterText");
|
||||
}
|
||||
|
||||
if (_tmpProText != null)
|
||||
{
|
||||
writer = _tmpProText.text;
|
||||
_tmpProText.text = "";
|
||||
|
||||
StartCoroutine("TypeWriterTMP");
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator TypeWriterText()
|
||||
{
|
||||
_text.text = leadingCharBeforeDelay ? leadingChar : "";
|
||||
|
||||
yield return new WaitForSeconds(delayBeforeStart);
|
||||
|
||||
foreach (char c in writer)
|
||||
{
|
||||
if (_text.text.Length > 0)
|
||||
{
|
||||
_text.text = _text.text.Substring(0, _text.text.Length - leadingChar.Length);
|
||||
}
|
||||
_text.text += c;
|
||||
_text.text += leadingChar;
|
||||
yield return new WaitForSeconds(timeBtwChars);
|
||||
}
|
||||
|
||||
if(leadingChar != "")
|
||||
{
|
||||
_text.text = _text.text.Substring(0, _text.text.Length - leadingChar.Length);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator TypeWriterTMP()
|
||||
{
|
||||
_tmpProText.text = leadingCharBeforeDelay ? leadingChar : "";
|
||||
|
||||
yield return new WaitForSeconds(delayBeforeStart);
|
||||
|
||||
foreach (char c in writer)
|
||||
{
|
||||
if (_tmpProText.text.Length > 0)
|
||||
{
|
||||
_tmpProText.text = _tmpProText.text.Substring(0, _tmpProText.text.Length - leadingChar.Length);
|
||||
}
|
||||
_tmpProText.text += c;
|
||||
_tmpProText.text += leadingChar;
|
||||
yield return new WaitForSeconds(timeBtwChars);
|
||||
}
|
||||
|
||||
if (leadingChar != "")
|
||||
{
|
||||
_tmpProText.text = _tmpProText.text.Substring(0, _tmpProText.text.Length - leadingChar.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue