- Home /
Sync WaitForSeconds with Particles
I downloaded the Unity Particle pack and used an explosion in my game. I also want a sphere to appear or disappear based on current particle frame. I have calculated it to appear for 1 second, then hide for another.
First run goes ok, then the coroutine starts distorting time, eventually playing the animation on reverse of the particle, and then reaching proper display again. Any clues?
IEnumerator ActivateDeathSphere()
{
while (!hasExploded)
{
hasExploded = true;
foreach (GameObject card in cards)
{
GameObject deathsphere = card.transform.GetChild(1).gameObject;
deathsphere.transform.GetChild(0).GetComponent<MeshRenderer>().enabled = true;
}
yield return new WaitForSeconds(1f);
foreach (GameObject card in cards)
{
GameObject deathsphere = card.transform.GetChild(1).gameObject;
deathsphere.transform.GetChild(0).GetComponent<MeshRenderer>().enabled = false;
}
yield return new WaitForSeconds(1f);
hasExploded = false;
}
}
Answer by mechanicarts · May 25, 2018 at 05:44 PM
Alright, so I learned that I need to start the coroutine in Start. That solves the sync problem for about 5 runs but then it still starts to desync. The explosion duration stands at 4 seconds, and it seems pretty well loopable (seeing how it's made by unity). So why does my coroutine lag behind after a while?