I am using C# and I have a situation in which I need to wait for a coroutine to finish. However, the call for StartCoroutine is being done inside a bool function, so the yield keyword is not available to me. Essentially, the bool function is being returned before the coroutine can finish and set the return bool properly. Is there a way to wait for the coroutine without the yield keyword?
Here is the code:
Basically, what you are trying to do here fundamentally doesn't make sense. It sounds like it should work, but when you think about it, you're basically asking the entire program to halt, waiting for this one value to return. There's a reason why Coroutines work the way they do- they have to be able to act separately from the rest of the program.
Instead of using a method that returns a straight bool, split it into two methods-
Then, in your other script, call the StartScoreCheck when you want to send a request, and then poll PollGuestScores() every frame until the result returns successfully.
Possibly, you could have PollGuestScores return a datatype which includes an 'undefined' state, for before the result has returned-
Then make bPostScore not a boolean, but a ScoreInfo (and I guess change its name since it'd no longer be accurate), and set its state when the CheckGuestScores coroutine finishes.
answered Nov 17 '11 at 01:56 PM