Hello All,
So I’ve been working on a rudimentary dialogue system. Basically it works by displaying text sequentially, and to do this I am using a coroutine.
using UnityEngine;
using System.Collections;
public class TalkTrigger : MonoBehaviour {
bool currentlyTalking = false;
public string[] dialogue;
// Use this for initialization
void Start () {
}
void OnTriggerEnter2D() {
//PUT THE STARTER DIALOGUE HERE
GUIManager.PushTextBox(GUIInterface.instance.genericTextBox, GUIInterface.instance.genericText, "press SPACE to talk to me");
currentlyTalking = true;
}
void OnTriggerStay2D(){
if(Input.GetKeyUp(KeyCode.Space) && currentlyTalking == true)
{
Debug.Log("Should be talking now...");
StartCoroutine("DialogueStart");
}
}
//this is where sequential dialogue goes
IEnumerator DialogueStart(){
GUIManager.StartConversation();
foreach(string text in dialogue)
{
yield return StartCoroutine(Dialogue(text);
}
GUIManager.EndConversation();
currentlyTalking = false;
}
IEnumerator Dialogue(string text){
GUIManager.PushTextBox(GUIInterface.instance.genericTextBox, GUIInterface.instance.genericText, text);
yield return new WaitForSeconds(5);
GUIManager.PopTextBox(GUIInterface.instance.genericTextBox, GUIInterface.instance.genericText);
}
}
now this script works as expected, but, when i try to change:
yield return new WaitForSeconds(5);
to
yield return Input.GetKeyDown(KeyCode.Space);
All of the text flies by, and doesn’t actually wait for the user’s next press.
Is there something about the default input methods that allow this to happen? Is there a way to control the floodgate so that the coroutine pauses at each point I need user input?
Thanks in advance