Hi, I have a spaceship with 2 guns. I wanted to shoot them alternately. Like that:
So I wrote that script:
public GameObject shot;
void Update () {
FiringShots ();
}
void FiringShots(){
if (Input.GetButton("Fire1") && Time.time > nextFire) { //firing blasts
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}
if (Input.GetButton("Fire1") && Time.time > nextFireB) { //firing blasts B with delay
nextFireB = Time.time + fireRateB;
StartCoroutine(InstantiateBShot ());
}
IEnumerator InstantiateBShot() {
yield return new WaitForSeconds(0.12f);
Instantiate(shot, shotSpawnB.position, shotSpawn.rotation);
}
Am I doing it right? I mean it does work, but is using IEnumerator & WaitForSecond function not to much? Is there better option maybe?