L
L
laykketyt2020-11-19 23:43:56
C++ / C#
laykketyt, 2020-11-19 23:43:56

How to make an event every second (Unity)?

How to make an event every second, please help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yuuki Wesp, 2020-11-20
@laykketyt

Use coroutines andWaitForSecondsRealtime

public class FooComponent : MonoBehaviour
{
    private void Awake()
    {
        StartCoroutine(YieldOneSecond());
    }

    IEnumerator YieldOneSecond()
    {
        while (Application.isPlaying)
        {
            yield return new WaitForSecondsRealtime(1f);
        }
    }
}

B
BasiC2k, 2020-11-20
@BasiC2k

Create a timer?

F
freeExec, 2020-11-20
@freeExec

Each Updatecheck to see if a second has passed since the last second.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question