- Home /
How do I start particle emission in c#?
Hi, I'm following a begginer's tutorial (since I have just started with programming). The Idea is that when the player aproach a collider, the particle emission should start. This is the code:
void LightFire (GameObject campfire)
{
ParticleEmitter[] fireEmitters;
fireEmitters = campfire.GetComponentsInChildren<ParticleEmitter>();
foreach(ParticleEmitter emitter in fireEmitters)
{
emitter.emit = true;
}
campfire.audio.Play();
Destroy(matchGUI);
}
Everything else in the code is run smoothly, the audio starts and the GUITexture is destroyed, but the emitters won't start. Can Someone tell me why?
TY
Answer by supernat · May 29, 2014 at 04:02 AM
It's one of the following most likely:
1) fireEmitters is coming back null. Which means the children in your campfire game object do not contain any ParticleEmitters.
2) The emitters are there, but they are not active (as in enabled, not as in emitting).
3) The emitters are there and emitting but not where you think they are in the scene (maybe they somehow got moved to another part of the world)
4) The emitters are emitting particles in a render layer that is not being rendered by the current camera (it's cull mask rejects them).
5) Lighting is wrong in the actual game but works fine in the Scene editor (so you see it in the scene and not in the game). For this one, you should be able to select the emitters on the campfire gameobject in the scene editor while the game is running and see quads rising up as particles
6) The particles are so small you can't see them in-game.
It's none of the above. I have two particle Systems attached to the campfire (one is fire, the other is Smoke). For what I understand, there is two checks that needs to be checked for the Emitter to emit particles. One is the Emission, and the other is the Play on awake. I tried to leave one checked and the other not and in the other system I tried to do it otherwise, and none work.
If I check both the works fin, but they start emitting at the start of the scene which is not the idea, the player must start the Fire by colliding with it.
Any other idea?
Open the scene editor while the particles should be active, click on the fire and/or smoke emitter, and is the emit flag set in the Inspector? I didn't think particle emitters had a Play on Awake. Particle Systems do.
Are you absolutely sure you are using Particle Emitter and not Particle System, so you're running an older version of Unity I take it? If it is getting into line 7 above (which is the item #1 in my answer), then I have no further idea.
I'm using a Particle System. I'm confused, is there a particle Emitter other than the one that comes with the Particle System? What code should I use?
I did what you sugested with the Inspector set on both Particle System and nothing happens...
Any other sugestion?
I'm using Unity 4.3.4
In version 3.5, Unity introduced a new particle engine.
ParticleEmitter is the old system (also called "Legacy").
ParticleSystem is the new system (also called "Shuriken").
They leave both classes exposed so that old games don't break. The vast majority of new development is done with ParticleSystem
.
I'm using Particle System, but still can't manage to make it work. This is the code as I undestood it for the link you provided.
void LightFire (GameObject campfire)
{
ParticleSystem[] fireEmitters;
fireEmitters = campfire.GetComponentsInChildren<ParticleSystem>();
foreach(ParticleSystem system in fireEmitters)
{
system.Play;
}
campfire.audio.Play();
Destroy(matchGUI);
}
But now the console gives me this error
Assets/Scripts/Inventory.cs(70,44): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Could you help me a little bit more...
DUH!! I forgot the () after Play... IT WOR$$anonymous$$S!!! Thanks for the help!!
Your answer
