Hi all,
I am still working on the TopDownShooter and although I asked about the coroutines before I am having difficulties implement this method.
I want to make some explosions when the boss-enemy ship gets destroyed. But I want to implement a series of explosions, like a second delay in between and in different spots of the ship. I have created an explosion prefab and referenced it on the boss-enemy script as well as an array of transforms. I wrote the following code.,
void BigBossExplode()
{
if (bigBossHealth <= 0)
{
bigBossExploding = StartCoroutine(BigBossBoom());
}
}
with;
IEnumerator BigBossBoom()
{
for (int i = 0; i < expolsionPositions.Length; i++)
{
GameObject exp = Instantiate(explosionBigBoss, expolsionPositions[i].transform.position, expolsionPositions[i].transform.rotation) as GameObject;
yield return new WaitForSeconds(1);
Destroy(exp, 2f);
}
// yield return new WaitForSeconds(2);
Destroy(gameObject);
}
and the BigBossExplode() method is called inside Update().
Now my problem is that the explosion game object gets called a million times. What I want is that the explosion instantiates once and once again on the other designated spot after a second and so on but now it is like that it is called a bunch of times on the first spot and again a bunch of times on the other spot after a second and so on.
What I thought might be wrong is that since the update is called every frame and the condition for the coroutine to start is met after the bigBossHealth hits the 0 mark, the coroutine is called many times which results in a million instantiated explosion game object. But I couldn’t figure out a workaround.
What am I missing?
Thanx in advance…=)