Last active
August 6, 2016 10:35
-
-
Save simon-heinen/091808eb97cf42757afdf7653670e21d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
public class TimerCountdown { | |
/// <summary> | |
/// Creates a timer which will return true every x seconds. Usage example in a MonoBehaviour: | |
/// | |
/// private Func<bool> onTimerRestart = TimerCountDown.newTimeCounter(0.1f); // fire every 100ms | |
/// ... | |
/// void Update() { | |
/// if (!onTimerRestart()) { return; } | |
/// | |
/// </summary> | |
/// <param name="countdownInSec">The interval after which the timer resets</param> | |
/// <returns></returns> | |
internal static Func<bool> newTimeCounter(float countdownInSec) { | |
var timer = 0f; | |
return delegate { | |
timer += Time.deltaTime; | |
if (timer < countdownInSec) { return false; } | |
timer = 0; | |
return true; | |
}; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment