- Home /
Emit Particle when the parent gets collision
I'm making an evasion game where you have to evade objects with a ball in a random generated world. When that ball hits an object, that object has to emit a particle. But when the ball hits the object , that object doesnt emit a thing. And when the prefab of that object spawns again the particle is constantly emitting.
this is the code i used to emit the particle the private var goan gets a boolean from the object (true = collision on object)
 private var hitParticles : ParticleEmitter;
 private var  goan = FlasherScript.ParticleEmit;
 function Start () { 
     hitParticles = GetComponentInChildren(ParticleEmitter);   
 
     if (hitParticles) {
         hitParticles.emit = false;
     }
 }
 
 function Update () {    
     if(goan == true) {
         Emitten();
     }
 }
 
 function Emitten() {
     hitParticles.emit = true;
     yield WaitForSeconds(3);        
     hitParticles.emit = false;
 }
What is "FlasherScript.ParticleEmit" ?
Also, you said "When that ball hits an object, that object has to emit a particle. But when the ball hits the object , that object doesnt emit a thing." ... I believe you meant something else there, so try clarifying this sentence. It will help us better understand what you are trying to achieve here.
Answer by Waz · Jun 21, 2011 at 11:56 AM
You are only initializing goan (i.e. once). Try something more like this:
 private var hitParticles : ParticleEmitter;
 
 private var goan = false;
 
 function Start () { 
     hitParticles = GetComponentInChildren(ParticleEmitter);   
 
     if (hitParticles) {
         hitParticles.emit = false;
     }
 }
 
 function Update () {
     if (FlasherScript.ParticleEmit && !goan) {
         goan = true;
         Emitten();
     }
 }
 
 function Emitten() {
     hitParticles.emit = true;
     yield WaitForSeconds(3);        
     hitParticles.emit = false;
     goan = false;
 }
You could simplify it a lot further too (the goan variable isn't really needed at all), but the above hopefully highlights the mistake.
Answer by Hasjbrownie · Jun 21, 2011 at 12:12 PM
Thx , now the partical emits when it collides , strange thing is they don't stop emitting.
But you were a great help, Big Thanks! ;)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                