Showing and hiding guiText after a key is pressed

Here is the thing. First I’m showing an animation of a rotating cube, then after 4 seconds I display a speech ballon (Gui Label). The balloon should be visible until the user presses the Spacebar. After this another speech ballon is shown. Then again the user needs to press the Spacebar to hide it. In total I show 3 speech ballons and after that is finished I play an animation. Here is the code:

function Intro()
{
	yield WaitForSeconds(4);
	gameObject.Find("Cubo Text").SendMessage("Show",0); // This calls a function that displays the correct message
	while (!Input.GetKey("space")) yield;
	gameObject.Find("Cubo Text").SendMessage("Show",1); 
	while (!Input.GetKey("space")) yield;
	gameObject.Find("Cubo Text").SendMessage("Show",2);
	while (!Input.GetKey("space")) yield;
	gameObject.Find("CuboB").animation.Play("roll");
	
}

This function is called in Start() . The problem is that I can see the first speech balloon, but after pressing the Spacebar I can’t see any other baloon and the animation starts inmediatly. Any ideas why this happens and how to solve it?

Hey there!

This should not be called in Start(). Start is literally only called at the initialisation of a script, so at the beginning of runtime. After the start of runtime, it is not called again. Therefore after the very start of runtime, your key inputs aren't being received. That's what Update() is for!

I'd say go about you're script like this:

var balloonNumber : int = 0;

function Start() {
    cuboText = gameObject.Find("Cubo Text");
    cuboB = gameObject.Find("CuboB");
}

function Update() {

    InvokeRepeating("SpeechBubbles", 4, 0);

}

function SpeechBubbles() {
    cuboText.SendMessage("Show", balloonNumber);
    if (Input.GeyKeyDown(KeyCode.Space) && balloonNumber < 2) {
        balloonNumber++;
        } if (balloonNumber == 3) {
            cuboB.animation.Play("roll");
        }
}

See how you go with that. Klep