Created
December 30, 2018 12:51
-
-
Save eiyaya/e52e54639dd20e7b0c5452988b8fb2f3 to your computer and use it in GitHub Desktop.
Unity3d Timer
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
IEnumerator Start() { | |
while(true) { | |
yield return new WaitForSeconds(1f); | |
OutputTime(); | |
} | |
} | |
void OutputTime() { | |
Debug.Log(Time.time); | |
} |
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
void Start () { | |
InvokeRepeating("OutputTime", 1f, 1f); //1s delay, repeat every 1s | |
} | |
void OutputTime() { | |
Debug.Log(Time.time); | |
} |
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
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
https://answers.unity.com/questions/1220440/how-to-display-call-a-function-every-second.html