- Home /
how to turn on an emitter with another emitter?
Hi,
I currently have a plane (camp fire) that has a fire emitter attached to it, I then have a flame thrower attached to the player. how would I go about creating it so that the emitter on the plane turns on its emitter when the player fires his flame thrower toward the planes collider? in addition i would like the point light to also turn on and off with the emitter but my coding is very poor.
I have my plane with the following C# scipt attached to it, isTrigger & convex are both ticked on the planes collider and a point light has been added as the child of this. myEmitter has been assigned with the flame thrower (drag and dropped)
public class firetrigger : MonoBehaviour {
public ParticleEmitter myEmitter = null;
void OnTriggerEnter(Collider other){ if(other.CompareTag("Player")) myEmitter.emit = true ; }
}
my flamethrower also has a world particle collider attached with "send collision message" ticked and the tag "player" attached to him.
Thanks in advance, I dont know what I would do without this site.
Answer by hijinxbassist · May 25, 2012 at 12:31 AM
One thing with this, you say myEmitter=null and then later tell it to emit. If there is no emitter, how will it emit? You could pass the emitter, but no reason to if you set it in the inspector. So heres what weve got:
A variable for the emitter with the fire emitter assigned to it from the inspector and emit set to false.
A variable for the point light with the light assigned from the inspector, the point lights enabled var set to false.
When particles collide with the fire pit plane, make fire pit emitter emit and turn on the light.
-
On FirePit:
public class firetrigger : MonoBehaviour
{
void OnParticleCollision(GameObject other)
{
myEmitter.emit = true ;
myPointLight.enabled=true;
}
}
$$anonymous$$y mistake, even though I was telling it that it is null, I assigned it through the inspector. I should have mentioned this before.
I added these two lines above what you wrote and assigned them through the inspector, the particle system works perfectly now.
public ParticleEmitter myEmitter = null; public Light myPointLight = null;
to turn the point light on when the flames are ignited I added...
myPointLight.intensity = 6 ; //on the 14th line
All works perfectly, thanks for your help.
@coolkid808 No prob, there is one more condition you can surround the inside of the collision code with,
if(!myEmitter.emit) //if emit is false run the code
{
//Working code
}
This way it will only run the "Working code" once, either way works though.