- Home /
How to display a message, wait for keypress and again and again?
I tried doing this with a coroutine, and it waits for the keypress before showing the message, but once I press the key all the messages are showed at the time.
I want to make something like this:
Debug.Log("Message 1");
-Wait for key press-
Debug.Log("Message 2");
-Wait for key press-
Debug.Log("Message 3");
...
So that first message is displayed at the beggining, then when I press a key message 2 is displayed but not message 3, and once I press a key again, then message 3 is displayed (and again for a lot of messages).
So as you can guess, it's to make a dialogue. Any help? :)
Answer by 767_2 · Nov 08, 2014 at 08:43 PM
you can count number of times that the has been pressed
int number=0;
if (Input.GetKeyDown("space")){
number++;
if(number==1)
Debug.Log("Message 1");
else if(number==2)
Debug.Log("Message 1");
else if(number==3)
Debug.Log("Message 1");
}
Your answer
Follow this Question
Related Questions
problem with using classes and coroutines 1 Answer
Quaternion.Lerp inside a Coroutine 2 Answers
yield return request never returns 2 Answers
Insantiation of a Coroutine Causes multiple clones 0 Answers