So I have this problem that in the middle of the game the gun particles stop appearing. I can’t figure out why this is happening since every indication is that they should be there. It happens at random with no indication that it’s connected to anything (like position of the ship or movement etc.) They will stop appearing for a while and then start appearing again inexplicably.
When I press space bar the following is true:
-Emission is checked off as active.
-The sound effect I have added to the guns plays.
-Enemies directly ahead of the guns do not die (i.e. the particles aren’t invisible or something).
-If I add a print statement to the foreach loop, it prints in the console.
-Guns are both active.
-There are no errors in the console.
-Sometimes one gun will shoot but not the other, even though they are identical except their position.
Why is this happening, has anyone experienced this before?
void ProcessFiring()
{
if (CrossPlatformInputManager.GetButton("Fire"))
{
ActivateGuns(true);
}
else
{
ActivateGuns(false);
}
}
void ActivateGuns(bool isActive)
{
foreach (GameObject gun in guns)
{
var emissionModule = gun.GetComponent<ParticleSystem>().emission;
emissionModule.enabled = isActive;
bool gunSoundActive = gun.GetComponent<AudioSource>().isPlaying;
if (isActive && !gunSoundActive)
{
gun.GetComponent<AudioSource>().Play();
}
}
}
}