The docs say that you can use OnCollisionStay as a coroutine if you use yield, but do not describe the semantics of it.
This seems like it would be useful to answer questions like "Have these two objects been colliding for X amount of time?" Without a coroutine you need instance variables to track this between calls (yuk).
1. Is there a separate co-routine running for each object colliding with the monobehaviour? This seems like the most logical way.
2. While you are yielding in OnCollisionStay, could it have been called again and started a new Coroutine?
3. When you return from your yield call, is there any guarantee that the objects are still colliding?
It might just be that the answers are #1 yes, #2 yes, #3 no. Which doesn't make it very useful for answering the question of "Have these two objects been colliding for X amount of time?"
↧