I’m execute a large piece of code and it freezes everytime.
I’m trying to execute this code in the background so it doesn’t freeze all game, but this seems to be imposible since Unity isn’t thread friendly (thing that I don’t understand).
Any suggestions?
I can’t use threads since I’m using random class.
You can use threads in Unity with the limitation that anything using the Unity API/Rendering must be called on the main thread. So depending on what your background task is doing this may be a viable option.
Otherwise you can use Coroutines which is a sort of cooperative multitasking that allows you to easily spread work across frames.