//Coroutine for incrementing timer over time private IEnumerator countDown(CountdownDelegate functionToExecute) { while (Time.realtimeSinceStartup < endTime) { print(endTime - Time.realtimeSinceStartup); yield return(new WaitForSeconds(updateInterval)); } functionToExecute(); }
//Starts counting from 0 public void countDownAndExecute(float duration, CountdownDelegate functionToExecute) { StopCoroutine(countDown(functionToExecute)); endTime = duration + Time.realtimeSinceStartup; StartCoroutine(countDown(functionToExecute)); }