How to make button press function work only in between # seconds? For example, allow user to press E at any time, but execute, for example, animation every 5 seconds? I've tried Invoke but it doesnt seem to work as it should. I've also tried timestamp and StartCoroutine (waitforseconds).
Here's what I got so you can see:
void Update()
{
if (triggerIsOn && Input.GetKeyDown(KeyCode.E))
{
drinkAmin.Play("DrinkVodka");
StartCoroutine(letsWait());
}
}
And
IEnumerator letsWait(){
Debug.Log ("lets wait works!");
yield return new WaitForSeconds (5);
TakeAshot ();
}
It all works, but not by 5 seconds in between, but rather it works every 5 seconds after each button press. So, this doesn't work as it should. Can anyone help me? A bit lost here. Thanks!