Question by
eannoni · Sep 07, 2020 at 08:19 AM ·
inputcoroutinewaitforseconds
Coroutine getting player input before timer runs out help
I am new to Unity so I apologize for my poor explanation:
I have a turn-based game where I need the player to react in a certain amount of time by pressing one of two buttons. If the time runs out, it's game over, but if a button is pressed within the time-frame, the coroutine needs to exit and continue the program.
I think I need a coroutine GetPlayerInput() that needs to WaitForSeconds() while also checking if a button has received input. How can I do both of these at the same time?
Thanks!
Comment
Answer by xxmariofer · Sep 07, 2020 at 01:05 PM
bool receivedInput = false;
IEnumerator GetPlayeInput(int amount)
{
int iterator = 0;
while(iterator < amount && !receivedInput)
{
iterator += Time.deltaTime;
yield return null;
}
}
public void ReceiveInput()
{
receivedInput = true;
}