- Home /
how to check button click in between running function ?
One of my function is running and I have to detect button click in between, then how do i check button click ?
Either stop function on half way until button click.
Or have to detect button click as fast as possible.
Considering first option, Can I stop any function half way and re-run (From where function stopped) after button click ?
Note: Function is normal function not Update or Start.
Answer by SirPaddow · Aug 19, 2019 at 08:24 AM
What you want is a coroutine. https://docs.unity3d.com/Manual/Coroutines.html
Something like this:
public class FuncWaitingForButtonClick : MonoBehaviour
{
public bool buttonWasClicked;
public void Start()
{
StartCoroutine(Function());
}
private IEnumerator Function()
{
// Do stuff before click
while (!buttonWasClicked)
{ // this loop will return as long as the bool is false
yield return null;
}
// Do stuff after click
}
}
Thank-You very much man - Lots of Love ! This exactly worked for me :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
how do I compare all the keys and values from one dictionary to another? 1 Answer
Need help in the stone throwing mechanic with aiming for mobile in Unity3d 1 Answer
How to Find the Sum of each Individual item / array out of range 0 Answers
How would buttons in a Chose Your Own Adventure Game work? 1 Answer