So I have this for loop, that’s used to help replicate how a firework launcher would shoot off fireworks.
void launchFireWerks(){
if (_NumLaunches != 0f) {
for (int i = 0; i <= _shots; i++) {
GameObject firewerkToLaunch = Instantiate (Resources.Load ("FireWorks/" + _FireWerkName))as GameObject;
firewerkToLaunch.transform.position = new Vector3 (_lauchLoc.position.x, _lauchLoc.position.y, 3f);
//Add random angle
_angleMod = Random.Range (-1f, 1f);
//Actual launch
firewerkToLaunch.GetComponent <Rigidbody> ().useGravity = true;
firewerkToLaunch.GetComponent <Rigidbody> ().AddForce (_angleMod, _launcherForce, 0, ForceMode.Impulse);
print ("We have lift off! shot number " + i);
if (i == _shots) {
print ("This launcher has 1 less launch than before.");
}
}
}
}
It does the shooting part perfectly, but I need some way to slow it down/pause it between shots, cause currently it iterates through the loop in about 1ms and is basically useless. I attempted to recreate something similar in a coroutine but the logic did my head in and couldn’t get it to quite work the way I wanted.
Any help would be swell! it doesn’t have to stay as a forloop!