Hi, I am writing the following code within a MonoBehaviour class:
Under a certain condition, I want to activate a button, and wait until the player press this button. Only then I want to move to next phase of the game.
private void CallingFunc()
{
// do something
if(condition)
{
StartCoroutine(CoroutineFunctionWrapper());
}
// Do more staff
}
private IEnumerator CoroutineFunctionWrapper()
{
yield return StartCoroutine(CoroutineFunction());
}
private IEnumerator CoroutineFunction()
{
// isButtonSelected is a member of the class,
// which will be set to true when the user hit a button
isButtonSelected = false;
SetButtonActive(true); // Set this button as active, show it on screen
yield return StartCoroutine(WaitForButtonSelected());
isButtonSelected = false;
}
private IEnumerator WaitForButtonSelected()
{
while(isButtonSelected == false)
{
yield return new WaitForSeconds(1.1f);
}
}
But I see the CallingFunc continues and does not wait for the end of the coroutine.
During my tries, I added the CoroutineFunctionWrapper - it doesn’t work with or without it.
I also tried to change CallingFunc to be a coroutine, but it also doesn’t change anything. (Bottom line is that the game continues before the button was pressed by the player.
Any suggestions…?
Thanks!
Please notice that "button" is not a GUI element, but a GameObject.
– renanaI update my answer with your last comment
– Briksins