写字符串10秒钟

时间:2018-09-10 05:20:14

标签: c# string unity3d

我正在尝试一种实现自写文本的方式,就像您通常在2D游戏中看到的那样,但是我发现自己陷入了困境, 我猜我被卡住的单词

在这种情况下,什么是不错的google搜索?

private IEnumerator Narrative(string line, float seconds)
{
    transform.GetChild(narratorPanel).GetComponent<CanvasGroup>().alpha = 1f; /* Begin narrative */

        for (int i = 0; i < 10000; i++)
        {
            while (seconds >= 0)
            {
                seconds -= Time.smoothDeltaTime;

            // ( seconds / line.Length ) = distance between each character in a timeframe

            // By the end the entire line must be displayed and chances are it's going to disappear immediately after the last character so I'll also have to implement some kind of padding so that the user is able to read it

            yield return null;
            }
        }

    transform.GetChild(narratorPanel).GetComponent<CanvasGroup>().alpha = 0f; /* End narrative */
}

1 个答案:

答案 0 :(得分:4)

以这种方式实施您的想法是否有原因?考虑以下方法,看看它是否适合您要实现的目标。

IEnumerator WriteText(string Text,float interval)
{
    string dummyText = "";
    foreach(char s in Text)
    {
        dummyText += s;
        //write to the text object
        _TextObject.text = dummyText;
        yield return new WaitForSeconds(interval);

    }