Hi, it seems that the 'yield return StartCoroutine' in OCE does not act properly when being invoked from the OnCollisionEnter() Method:
public class example : MonoBehaviour {
public GameObject instPrefab;
public Effects e;
public void Start() {e = Effects.CreateInstance<Effects>();}
public IEnumerator OnCollisionEnter(Collision col) {
Debug.Log("Collided!"); //<--happens
ContactPoint cp = col.contacts[0];
Vector3 pos = cp.point;
if (instPrefab) {
yield return StartCoroutine(e.ParticleEffects(instPrefab, pos));
Debug.Log("Done with Coroutine"); //Never happens
}
}
}
public class Effects : ScriptableObject {
public IEnumerator ParticleEffects(GameObject instPrefab, Vector3 pos) {
Debug.Log("Starting Co-Routine"); // <-Happens
GameObject inst = (GameObject) Instantiate(instPrefab, pos, Quaternion.identity);
ParticleEmitter pE = inst.GetComponent<ParticleEmitter>( );
while (pE.maxSize > 0) {
pE.maxSize -= 5 * Time.deltaTime;
yield return null; // return a null frame?
}
Debug.Log("End"); // <-- Still Does not happen
}
}
Is their something that I am missing? Or am I just unable to do this after the method OCE is invoked? Again, the problem $is not being able to Wait for a desired amount of seconds in the Coroutine, "ParticleEffects"