How to make timer?

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

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

1 Like

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");
    });
});
2 Likes

This is actually really impressive. Im telling you man flax has massive potential.

Ty for answer tho :slight_smile: