Wait untill player presses a button...

Hi all…

I`m trying to do a rpg battle, when player launches an attack to enemy, the guiManager writes a comment on a guiText, but what i’m looking for is to freeze game after each comment is written, and unfreeze it when player presses any key…

something like:

guiText.texture = "Player has attacked!";
yield WaitForSeconds(Input.GetButtonDown("jump"));

of course the parameter maybe wrong :wink:

with this, the game will continue its sequence only if player is pressing jump button…

any idea?

Thanks!

Hmm, normally wat I did is this

You could Start a Coroutine, than run a loop to check if the button has been pressed.

function Update() {
//check for attack
StartCoroutine("DoAttack");
}

function DoAttack() {
Time.timeScale = 0.0;
guiText.texture = "Player has attacked!";
while(!Input.GetButtonDown("jump")) {
yield;
}

Time.timeScale = 1.0;
}

If you want to have a varible that tells you if the game has been paused for the attack, just put an external varible and set it to true at the start of DoAttack, and set it to false at the end of DoAttack.

nice !.. thanks both… i will try those two options… greetings…

I agree. Co-routine will be more efficient.

Don’t launch a coroutine from Update like that though. You will quickly have thousands of coroutines running simultaneously. Just leave Update out altogether.

–Eric

Oops didn’t see that he was running co-routine from update. Yeah. Agree with Eric.

Hmm, mayb we can clean up the code even further by this

function watever()
{
guiText.text = “Player has attack”;
while ( !Input.GetButtonDown ( “Jump” ):wink:
{
// Wait till the jump button is true then break the loop
yield WaitForSeconds ( 0.1 );
}
// Type the following code here
}

Cheers