How to make an event every second (Unity)?
-
How to make an event every second, please help!Unity Game Engine Jacob Hutchinson, Jan 1, 2019
-
Use coroutines and
WaitForSecondsRealtime
public class FooComponent : MonoBehaviour
{
private void Awake()
{
StartCoroutine(YieldOneSecond());
}
IEnumerator YieldOneSecond()
{
while (Application.isPlaying)
{
yield return new WaitForSecondsRealtime(1f);
}
}
}Adeline McCall -
Create a timer?Evangeline Melton
-
Each
Update
check if a second has passed since the last second.Anonymous
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!