Is it possible to add a coroutine to an event? I'm experimenting with events, and it seems like it would be extremely useful. However, I've got to run a coroutine for one of the functions that will be assigned to the event. Don't know if I'm explaining this correctly so here's some code:
Basically what I want to do (but not a solution):
Is this even a viable approach? Or should I just do the long work around of reference and call the function?
Also thought about this:
But it doesn't work either.
And you can only add functions with the return type of IEnumerator:
And this is how you would add the function to the event:
Updated my answer. Everything works perfectly.
I'm not sure what your intentions are, but you can't start a directly coroutine from a static method since StartCoroutine is a member method from MonoBehaviour. Another problem is that the event handlers must be a coroutine, so they must return IEnumerator.
However there's a problem: only the last handler is called.
answered Mar 07 '12 at 07:41 PM