|
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: Event declaration: Basically what I want to do (but not a solution): My function: 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.
(comments are locked)
|
|
Surprising simple: 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.
(comments are locked)
|
|
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. So the last function added would be the only one to ever be called? That would defeat the purpose of using events wouldn't it?
Mar 07 '12 at 08:15 PM
SirGive
(comments are locked)
|
|
Your delegate needs to return an IEnumerator, as well as BookSelect's function, which is probably assigned from elsewhere. Then, you call StartCoroutine(bookSelect());
(comments are locked)
|
