I have a GameManager class which is a singleton, utility class. It controls scene transitions, scores, etc. It is a singleton because it holds global state that needs to shared across Scenes.
It does not inherit from MonoBehaviour so I can control its lifetime better (without resorting to DontDestroy… type functions).
I want to wait N seconds between scene transitions without blocking the UI (main) thread. However, all the way I know how to do such a thing in C# using TPL is coming up short because they end up calling the delegate (in this case, LoadNextLevel() function) from a different thread! Which Unity does not support / like :(.
Appreciate some help on how to accomplish this, thanks.
Debug.Log($"called from main thread: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
Task.Delay(2000).ContinueWith(t =>
{
Debug.Log($"called from continueWith: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
LoadNextLevel();
});