How to make timer?

What is the best way to add a timer through code? Unity equivalent:

private IEnumerator Wait()
{
return new WaitForSeconds(1);
}

You can use C# async tasks: to impl delay and then call back code on a main thread:

using System.Threading.Tasks;
using FlaxEngine;

Task.Run(async delegate
{
    await Task.Delay(3000); // delay in miliseconds
    Scripting.InvokeOnUpdate(() =>
    {
        // Do something on a main thread after async delay
        Debug.Log("Hey");
    });
});
1 Like