Hi there,
I want to run some algorithm that takes too long to do it in a tick and I don’t want the rest of the game to be frozen while the algorithm is running.
In my particular case, i have a level generator where players can adjust certain parameters using the GUI system and rotate the camera around a preview of the level. If they like the result, they can click a GUI button, the GUI disappears, and the camera zooms into the level.
For simple levels, the settings seem to be instantly applied, but more complex levels take a couple of seconds and I want the GUI and camera to be responsive and just show some icon while the new level is being generated (so people still see the old one, greyed out until the new result is there).
You can use System.Threading, but only for thread-safe .net functions, not Unity API functions. But you can still put time-consuming calculations in a thread, then use Unity functions at the end when necessary. See here for an example.
It's not that hard; I had to do the same thing with the beginning of my game, where all the hexagon tiles get instantiated and the vertices modified.
You know what part of your script is causing all the delay; there's some big whopping while or for loop. Stick a yield in at the end of that loop. (Inside!)
Now at the same time what I did was to have a plane with a black material in front of the camera, and the script that is looping makes it active at Start(), to cover up all the action going on in the background, and I have a string being printed OnGUI, saying "Preparing Map - XX%"
You can see it in action on my website, I have this very routine in a webplayer.