- Home /
Calling functions in a specific order.
I am writing a basic widget for a moving platform or obstacle of some kind. I have a function, Motion, that calls a group of other functions. The problem is that they are all called at the same time. How can I make the game wait for ForwardMove() to complete before calling yield and BackwardMove.
In addition, how could I get this to repeat or recur as long as moving == True? I tried a While loop but it caused everything to happen at the same time on every frame.
function Motion(){
if (moving){
yield WaitForSeconds(startpause);
ForwardMove(forwardtime);
yield WaitForSeconds(endpause);
BackwardMove(backwardtime);
}
}
Answer by jspease · Feb 28, 2012 at 08:54 AM
What you probably want to do is "chain" coroutines, like this:
function Motion()
{
while(moving)
{
yield WaitForSeconds(startpause);
yield StartCoroutine(ForwardMove(forwardtime));
yield WaitForSeconds(endpause);
yield StartCoroutine(BackwardMove(backwardtime));
}
}
@Eric, I prefer to write it too... It seems to be more reliable then.
Your answer
Follow this Question
Related Questions
Best way to make these tree iterations? Arrays? tags? nested etc 1 Answer
Running Functions in Order 0 Answers
while loop not looping 2 Answers
Loop a function in c#.HELP!!! 2 Answers
Loop a function 1 Answer