我想為我的對話創建自動打字效果。現在我將我的對話存盤在一個基于節點的編輯器中。當我現在想要讓文本慢慢輸入時,它會出現 2 次,只有第二次被輸入。
public class DialogController : MonoBehaviour
{
[SerializeField] private GameObject dialogUI;
[Header("Text")]
[SerializeField] private Text textName;
[SerializeField] private Text textBox;
[SerializeField] public float typingSpeed;
private void Awake()
{
ShowDialogUI(false);
buttons.Add(button01);
buttons.Add(button02);
buttons.Add(button03);
buttonsTexts.Add(buttonText01);
buttonsTexts.Add(buttonText02);
buttonsTexts.Add(buttonText03);
}
public void ShowDialogUI(bool show)
{
dialogUI.SetActive(show);
}
//loading in the text
//TODO typing in the text when loading it in.
public void SetText(string text)
{
textBox.StartCoroutine(Type());
IEnumerator Type()
{
foreach (char letter in text.ToCharArray())
{
textBox.text = text = letter;
yield return new WaitForSeconds(typingSpeed);
}
}
}
public void SetName(string text)
{
textName.text = text;
}
}
uj5u.com熱心網友回復:
因為你寫了這個:
textBox.text = text = letter;
全文會一直完整存在,全文的一個字母會一個一個的加進去。將其更改為
textBox.text = letter;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/391158.html
上一篇:Odoo-如何模塊化XML欄位
