Skip to content

Instantly share code, notes, and snippets.

@eiyaya
Created December 30, 2018 12:51
Show Gist options
  • Save eiyaya/e52e54639dd20e7b0c5452988b8fb2f3 to your computer and use it in GitHub Desktop.
Save eiyaya/e52e54639dd20e7b0c5452988b8fb2f3 to your computer and use it in GitHub Desktop.
Unity3d Timer
IEnumerator Start() {
while(true) {
yield return new WaitForSeconds(1f);
OutputTime();
}
}
void OutputTime() {
Debug.Log(Time.time);
}
void Start () {
InvokeRepeating("OutputTime", 1f, 1f); //1s delay, repeat every 1s
}
void OutputTime() {
Debug.Log(Time.time);
}
float elapsed = 0f;
void Update() {
elapsed += Time.deltaTime;
if (elapsed >= 1f) {
elapsed = elapsed % 1f;
OutputTime();
}
}
void OutputTime() {
Debug.Log(Time.time);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment