public class TextBoxManager : MonoBehaviour { public Text[] textBoxes; // 存储多个文本框的数组 public float delayBetweenTextBoxes = 0.5f; // 文本框之间的延迟时间 public float delayBetweenCharacters = 0.1f; private int currentTextBoxIndex = 0; // 当前显示的文本框的索引 void Start() { StartCoroutine(ShowTextBoxes()); } IEnumerator ShowTextBoxes() { // 逐个显示文本框 foreach (Text textBox in textBoxes) { textBox.gameObject.SetActive(true); // 激活文本框 // 逐个显示字符 string text = textBox.text; textBox.text = string.Empty; foreach (char c in text) { textBox.text += c; yield return new WaitForSeconds(delayBetweenCharacters); } yield return new WaitForSeconds(delayBetweenTextBoxes); // 等待一段时间 } // 当所有文本框都显示完毕后,将一个组件SetActive的值设置为true // 假设你要设置一个名为"YourComponent"的组件 YourComponent.SetActive(true); } }

Unity C# 代码:控制文本框逐字显示并激活组件

原文地址: https://www.cveoy.top/t/topic/qc1o 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录