- Home /
Question by
mclightning · Aug 01, 2012 at 08:02 PM ·
componentparticleemitterparticleemitter
Particle emitter object destroys itself
Hi fellows, im trying to create a flamethrower. i made a cube and attached particle renderer,mesh particle emitter,particle animator components on it. and then i attached following script to turn on & off the flamethrower but at some point emitting object i mean the cube destroys itself...
public class FlameThrower : MonoBehaviour {
public ParticleEmitter emitter;
void Start () {
emitter=(ParticleEmitter)GetComponent("ParticleEmitter");
emitter.emit=false;
}
// Update is called once per frame
void Update () {
if(Input.GetKey("z") && emitter.emit==false)
{
emitter.emit=true;
}
else
{
emitter.emit=false;
}
}
}
Comment
Answer by mclightning · Aug 01, 2012 at 09:12 PM
I just realized that i checked Autodestruct in Particle Emitter. sorry
I didn't even know there was an "Autodestruct" option! I repurposed another object and it already had the setting turned on. I couldn't figure out why my objects were being destroyed!
Answer by strachpr01 · Aug 01, 2012 at 08:17 PM
try
if(Input.GetKeyDown("z")&& emitter.emit==false)
{
emitter.emit=true;
}
if(Input.GetKeyUp("z"))
{
emitter.emit=false;
}