Accidentally posted twice due to site issues
What is the Unity-esque way for a yielding function to return a value to another yielding function?
In other environments, it is common to do something like:
getUsersMatchingCriteria() {
result = http_get(url, ...)
return result
}
anotherYieldingFunction() {
users = getUsersMatchingCriteria(...)
doStuffToUsers(users)
}
but I am having trouble figuring out how to do something similar in Unity. Yielding is done through coroutines, but coroutines can't return a result. After searching for an answer, I came across this answer, but that is an extremely elaborate workaround for something that seems like a common use case. I'm guessing there is a more-preferred way to do this in Unity, so instead of "how to return a value from a coroutine" I'm asking something more broad: how can I pass data between two pieces of yielding code? What is the Unity-esque standard for doing this?
My specific use case is that I have a function to roll a die -- it plays the rolling animation, and I want it to return the face-up value of the die when the animation completes. Another, also-yielding, function would use this when a user attacked a target to determine if their attack is a success.
Follow this Question
Related Questions
Invoke method is not called 2 Answers
Unity - Lines after yield not getting executed 0 Answers
C# Yield WaitForSeconds within For Loop 1 Answer
How to pass data between 2 yielding blocks of code? 0 Answers
Help with coroutines 1 Answer