Disabling Fire cancels all Particles?

Hi,

The way that the firing command works is by enabling/disabling the particle effect. However, when disabling the particle effect it cancels also ALL particles that have already been fired and are in mid-flight. The result is that the player has to keep the space bar pressed until the particles have hit the enemy which obviously feels very unnatural. So I’m wondering what’s the workaround for that, or will that be addressed in a later section?

4 Likes

Good observation. They do address it in a later section by turning off and on the emission of the particle system instead of setting the game object to active/inactive.

Oh didn’t realize the respond speed here is almost real-time haha. Thanks, I will just keep following the lessons then!

1 Like

Well, figured it out on my own … if anyone’s interested:

first, instead of referencing
[SerializeField] GameObject[] guns

use
[SerializeField] ParticleSystem[] guns

then in the foreach loop use

to fire:
foreach (ParticleSystem gun in guns) { gun.enableEmission = true; }

to stop firing:
foreach (ParticleSystem gun in guns) { gun.enableEmission = false; }

although visual studio tells me that this method is deprecated. Also tried ParticleSystem.Play() and .Stop(), but that didn’t work for some reason.

4 Likes

Nicely done!!

There is a way to do it without using the deprecated method that they do go over in a later lesson. Specifically, since you’ve already dived in:

// Assume you have some bool isActive that determines if you want to toggle the guns on or off
    foreach (GameObject gun in guns)  {
         var emissionModule = gun.GetComponent<ParticleSystem>().emission;
         emissionModule.enabled = isActive;
     }
6 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms