【发布时间】: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;
}
}
是的,我还是新手,所以不要恨我:'
【问题讨论】: