Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

alternately firing 2 guns C#

$
0
0
Hi, I have a spaceship with 2 guns. I wanted to shoot them alternately. Like that: ![alt text][1] [1]: /storage/temp/61251-delme.jpg 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?

Viewing all articles
Browse latest Browse all 592

Trending Articles