【问题标题】:How to skip a dialogue UNITY - Need help, the code for the dialogue works but not for skipping it :'如何跳过对话 UNITY - 需要帮助,对话的代码有效,但不能跳过它:'
【发布时间】:2022-01-22 23:52:15
【问题描述】:

伙计们,我在 Unity 中为对话系统编写了代码,但我对如何跳过它感到困惑。它运行良好,但我只需要它,所以如果需要的时间太长,我可以跳过它。

private IEnumerator StartDialogue()
{
    if (outOfRange == false)
    {
        int dialogueLength = dialogueLines.Length;
        int currentDialogueIndex = 0;

        while (currentDialogueIndex < dialogueLength || !letterIsMultiplied)
        {
            if (!letterIsMultiplied)
            {
                letterIsMultiplied = true;
                StartCoroutine(DisplayString(dialogueLines[currentDialogueIndex++]));

                if (currentDialogueIndex >= dialogueLength)
                {
                    dialogueEnded = true;
                }
                else
                {
                    if (Input.GetKeyDown(DialogueInput))
                    {
                        StopAllCoroutines();
                        currentDialogueIndex = dialogueLength;
                    }
                }
            }
            yield return 0;
        }

        while (true)
        {
            if (Input.GetKeyDown(DialogueInput) && dialogueEnded == false)
            {
                break;
            }
            yield return 0;
        }
        dialogueEnded = false;
        dialogueActive = false;
        DropDialogue();
    }
}

如你所见,我已经设置了代码,如果 currentDialogue >= dialoglength 那么第一个对话将结束,我尝试将此代码用于“else”,以便它可以停止协程并立即填充该框,但它仍然没有跳过

                else
                {
                    if (Input.GetKeyDown(DialogueInput))
                    {
                        StopAllCoroutines();
                        currentDialogueIndex = dialogueLength;
                    }
                }

是的,我还是新手,所以不要恨我:'

【问题讨论】:

    标签: c# c++ unity3d dialog


    【解决方案1】:

    如果我很理解你的所作所为,那么问题实际上出在 else if 块中,你会在该块中停止所有协程。

    问题是StopAllCoroutines() 有效地停止了在这个游戏对象上运行的所有协程。所以当你调用这个方法时,它会停止 StartDialogueDisplayString 协程。

    您缺少的是您在字符串末尾设置了currentDialogueIndex,但之后您不再显示文本。

    您只需要在跳过时显示全文,一切都已设置好,现在由您决定!

    希望有所帮助,没有人讨厌你;)

    【讨论】:

    • 我为 StopAllCoroutine 得到它,但对于显示部分我有点困惑。因为在这种情况下,显示对应于 dialogLines 的长度 dialogLength。所以我应该只发布对话线???
    • 您可以使用currentDialogueIndexdialogueLength 调用DisplayString。您应该在某处将所有对话线路设置为您的 Text 组件的 text 属性
    • 啊,好吧,让我试试。完成后我会回复你的!谢谢!!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多