【问题标题】:Unity pause text display in between stanzas wait for user inputUnity在节之间暂停文本显示等待用户输入
【发布时间】:2014-11-26 11:33:55
【问题描述】:

我有一个脚本,当前一个字母一个字母地显示对话文本。目前,它在我的 _stanzas 数组中滚动浏览每个文本字符串,而不会暂停。我想更改此脚本,以便它要求用户在脚本开始从 _stanzas 打印下一个文本块之前按键盘上的“Z”。我似乎无法弄清楚...这是我的代码。

使用 UnityEngine; 使用 System.Collections;

public class Text : MonoBehaviour {


public float LetterPause = 0.1f;
public GameObject text;
public GameObject box;
public GameObject name;
    private bool _textFinished;
    private int _textIndex;
    private string[] _stanzas;
int tracker;

    public void Start()
    {
    if (Application.loadedLevel == 1) {
                    _stanzas = new [] {
                            " It’s Terrence’s hat... ",
                            "He always was one to lose track of the" + "\n" + "material objects in life," + "\n" + "but to hold onto the immaterial forever.",
                            "I’ll carry it for him" + "\n" + "until I find him. "
                    };
            }


        _textFinished = true;
        _textIndex = -1;
    tracker = _textIndex;
    }

public void Update()
{   

    if (_textFinished)
    {
        if (_textIndex++ >= (_stanzas.Length - 1))
        {
            _textFinished = false;
            text.SetActive(false);
            box.SetActive(false);
            name.SetActive(false);
        }

        if (_textFinished){
                SetText(_stanzas[_textIndex]);}
    }
}

    private IEnumerator TypeText(float waitTime, string text)
    {
        _textFinished = false;

        guiText.text = "";

        foreach (var letter in text)
        {
            guiText.text += letter;

            yield return new WaitForSeconds (waitTime);
        }

        _textFinished = true;
    }

    private void SetText(string text)
    {
        StartCoroutine(TypeText(LetterPause, text));
    }


}

【问题讨论】:

    标签: user-interface text unity3d


    【解决方案1】:

    改变

    if (_textFinished)
    

    if (_textFinished && (Input.GetKeyDown(KeyCode.Z) || _textIndex < 0))
    

    【讨论】:

      猜你喜欢
      • 2016-05-02
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 2014-12-24
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      相关资源
      最近更新 更多