I guy.
I wanna stop my game until a Coroutine and/or function is over. I cannot really find a way to do that. actually, I just want to stop action on GameObject during this time.
Does someone know how to do that please.
Would be grateful.
Thank you very much.
in C# you can use
yield return StartCoroutine(MyRoutine());
And it will wait until the coroutine is finished. This however has to be nested within a coroutine itself.
I’m not sure why you want to block your game with a coroutine though. The entire purpose of Coroutines is that they are nonblocking.
You can however use a boolean to record the state of the coroutine.
bool isRunning = false;
void Update()
{
if(!isRunning)
{
//Do Stuff
}
}
IEnumerator MyRoutine()
{
isRunning = true;
//doStuff
isRunning = false;
}
Because Coroutines are not really Async you can be sure that Update and MyRoutine will never be processed at the same time, and so this allows your update loop to stop while you are in a specific coroutine.
You can also disable the specific Component (but be careful as that also disables coroutine updating).
Thx for you reply.
Actually I don’t really where is the problem comes from but when I write files there is a delay between the end of the writing function (&close file) the opening of permission to rewrite the file. So if I click too much fast, there is a problem with opening permission.
Actually I use a quite dirty stuff which is a delay …