- Home /
Stop executing function and make it wait until an another function is finished and only then continue execution
Hi!
I am trying to do the following:
I have some floors with cubes and two crushers (on the left and right sides of the floors) in my scene. When one of the floors is full of details (I check all the floors one by one if they are full in one function), I move the crushers to it, move both of them to the middle of the floor in order to destroy them.
The problem is that when the last cube on the floor is destroyed, all the other floors decrease their position, but the crushers are still in the middle. I need to move them back and only then all the cubes can have their position decreased. (Right now - the last cube is destroyed - move all the floors lower immediately)
Smth like this SHOULD happen: The last cube on the floor is destroyed, we freeze the execution, run an another function to move the crushers to appropriate positions, and when it's done we can unfreeze the function and let the cubes move lower.
Like:
/ 2- Cube 1, Cube 2,.../
CrusherL /1- Cube 1, Cube 2, Cube 3 / CrusherR
Then:
/ 2- Cube 1, Cube 2.../
CrusherL, CrusherR
And then:
/ 2- Cube 1, Cube 2,.../
CrusherL /......................................./ CrusherR
And at last:
CrusherL / 1 - Cube 1, Cube 2,......./ CrusherR
I know about System.Threading.Thread.Sleep, but it requires time and I don't know how much time I need to clean one of the floors.
Thanks in advance.
Answer by whydoidoit · Mar 05, 2014 at 01:38 PM
This is an ideal use of coroutines. You can have one coroutine yield another and continue execution when it is complete.
Check out the coroutine tutorial
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How long do movement controls take? 2 Answers
Accurate millisecond timed thread 2 Answers
Damage over time while colliding. 1 Answer
Running Costly Code over Time 1 Answer