It should be a simple task but I’m struggling with it and google searches are not helping.
I would like to see a sample C# script performing this. Preferably with coroutines.
UPDATE:
Apparently I did not make my original question clear enough.
The bool starts in the false state.
When the button is tapped, the bool becomes true for a limited time.
When the time limit is reached, the bool returns to false state.
I am not trying to delay anything. Just have a bool that starts false, become true for a limited time after a button tap.
1: Invoke ( “MethodName”, delayTime);
e.g. Invoke ("DelayClick",0.5f);
For best practice you can check if(isInvoking("methodName")) before calling method
2 . By Coroutines
e.g.
private bool temp = false;
//Call this method on the click of the mouse
void MouseClick(){
temp = true;
StartCoroutine(CoroutineName(0.5f)); // lets say 0.5f
}
IEnumerator CoroutineName(float delayTime){
yield return new WaitForSeconds ( delayTime) ;
temp = false
// your code will go here
}
itsharshdeep: Your second method doesn’t work for me. I’m trying to have a boolean be true for a limited time, not delay the switching of a boolean (as I understand your code does).