Wait for Input

Currently I’m using a for loop for my chat system. After my first few lines of text display I want to make it so instead of using yield WaitForSeconds, use something like a wait for input. So stop on that line of code until I press Space Bar and then continue. I tried this by creating a var for WaitForSeconds that would be set really high such as 9999999 and then by pressing space bar it makes it 0 but after yield WaitForSeconds is set it looks like it can’t be changed. So I’m kind of stuck currently

can you expand a little on what you are trying to do, the bigger picture?

I would have expected a chat system to run off a trigger like “return” for send message, waiting for space bar seems a little odd, so i’m guessing what you are doing isn’t obvious from the simple explanation of “chat system”.

For this an NPC is talking and Spacebar allows the next message to display. I’ll just write a quick example

//call chat function to talk
function chat () {

Debug.Log("HI !");

//Need some piece of code here that will wait until the User presses spacebar until displaying the next line of code

Debug.Log("Bye");

}

It seems to me what you need is a coroutine. Check out the tutorial for coroutines here: http://unity3d.com/learn/tutorials/modules/intermediate/scripting/coroutines

Check for the press of the spacebar in the coroutine and yield when the spacebar is pressed.

I’m still a little confused since they didn’t provide an example for input. Is yield; the part that pauses until something occurs? Maybe you could edit my example to show me how it might be setup to handle wait for input.

// hi!

while (!Input.GetKeyDown(KeyCode.Space))
{
    yield return null;
}

// bye!