So you should be able to do that, and you've pretty much got the right idea.
I'd do it like this
public class Example : MonoBehaviour
{
bool buttonPressed = false;
public void ButtonWasPressed()
{
buttonPressed = true;
}
public void FunctionThatCallsCoroutine()
{
buttonPressed = false;
StartCoroutine(WaitForButtonPressAndDoSomething());
}
public IEnumerator WaitForButtonPressAndDoSomething()
{
while (!buttonPressed)
yield return null;
DoSomething();
}
public void DoSomething()
{
Debug.Log("OMG BUTTONPRESS!")
}
}
I haven't tested/compiled this but I'm 99% sure it'll do what you want. "yield return null;" will halt the function until the next frame, upon which it'll try the loop again and halt again if the button hasn't been pressed. When buttonPressed becomes true the loop will exit and your DoSomething function will be called.
Comments
I'd do it like this
I haven't tested/compiled this but I'm 99% sure it'll do what you want. "yield return null;" will halt the function until the next frame, upon which it'll try the loop again and halt again if the button hasn't been pressed. When buttonPressed becomes true the loop will exit and your DoSomething function will be called.
Hope this helps ^_^