IEnumerator Shoot() { // We need to wait before the particle system is fully ready before we start to call for our emission while (!particles.Initialized()) { yield return(null); } // Set variables float rotationSpeed = 360f / numberOfParticles; float timeDone; // Set particle count to match the amount needed particles.particleCount = numberOfParticles * cycles; // Wait before emission starts (if applicable) if (yieldBeforeEmission > 0) { timeDone = PlaygroundC.globalTime + yieldBeforeEmission; while (PlaygroundC.globalTime < timeDone) { yield return(null); } } // Loop through every cycle (c) and particle (p) for (int c = 0; c < cycles; c++) { for (int p = 0; p < numberOfParticles; p++) { // Emit a particle in rotated direction particles.Emit(thisTransform.position, thisTransform.right * force, isSameLifetime? maximumLifetime : Random.Range(minimumLifetime, maximumLifetime), color); // Rotate towards direction thisTransform.Rotate(rotationNormal * rotationSpeed); // Wait for next emission (if applicable) if (yieldBetweenShots > 0) { timeDone = PlaygroundC.globalTime + yieldBetweenShots; while (PlaygroundC.globalTime < timeDone) { yield return(null); } } } // Wait for next cycle (if applicable) if (yieldBetweenCycles > 0) { timeDone = PlaygroundC.globalTime + yieldBetweenCycles; while (PlaygroundC.globalTime < timeDone) { yield return(null); } } } // Return if not in Play Mode in Editor #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { yield break; } #endif // Wait for action when last particle's lifetime is over switch (whenDone) { case WhenDoneCircleShot.Inactivate: yield return(new WaitForSeconds(maximumLifetime)); gameObject.SetActive(false); break; case WhenDoneCircleShot.Destroy: yield return(new WaitForSeconds(maximumLifetime)); Destroy(gameObject); break; } }