Better way of activating particles?

Hi guys,
I was wondering if someone could tell me if there is a better way of activating and deactivating particles, because even in the last course, when i tried to add sound effects to each bullet fired i had to make a silly solution with a third, invisible particle shooting upwards above the ship in an invisible gameObject and then that game object made the sound, making it look like it’s the normal front cannons shooting and making the sounds.

So, to recap. Suggestions to implement a sound when a bullet is fired in this current way we are doing things. Or maybe some other way that you would do that.

Looking forward to responses :slight_smile:

Instead of just turning on the particle emitter on pressing fire button and stopping it with release, I keep an internal timer variable for fire delay instead of letting the particle system decide the rate.

On pressing fire, I call Emit(1) on the particle system to make it emit a single particle when appropriate, play a sound effect at the same moment, and set the delay timer to when it’s appropriate to be able to fire again.

1 Like

My solution involved timing… Figuring out how often a bullet fires, and playing the firing sound at those intervals…

shotInterval=1/emission;  //Note that it's hard to get this value from the Particle System, so I made emission a slider

So if Emission is say… 1 (1 per second)… then in Update

 if(firing)
       {
             float timer+=Time.deltaTime;
             if(timer>shotInterval)
                   {
                        audioSource.Play();
                        timer=0;
                    }
         }

I used the ParticleSystem.Emit() function as well which allowed for easy adjusting of Rate of fire and also fired immediately when in range instead of the delay from toggling emitting on/off.

Here is my Co-routine:

private IEnumerator FireGuns() {
        while (isFiring) {
            guns.Emit(1);
            yield return new WaitForSeconds(fireDelay);
        }
    }

You could easily trigger the audio in this while loop.

Privacy & Terms