- Home /
how to emitt a particle effect on touch
Hello, im new to unity and im making a 2.5d game. What I want to do is emitt a smoke particle effect when a bullet touches an enemy. Sadly Particle effect doesn't emitt, I dont know what I have done wrong. I hope you understand what I said. Thank you for helping me.
var smokeFX : ParticleEmitter;
var damage : int = 1;
function OnTriggerEnter (Bullet : Collider)
{
if (particleEmitter) {
particleEmitter.emit = true;
yield WaitForSeconds(0.5);
particleEmitter.emit = false;
}
if(Bullet.gameObject.tag=="Enemy1"){
Bullet.gameObject.GetComponent(EnemyBehaviour).TakeDamage(damage);
}
}
[Edit by Bérenger : Code formatting]
How fast are your bullets? If they are pretty slow, try this. If they are fast, use RayCast ins$$anonymous$$d.
Answer by seedoubleyou · Mar 03, 2012 at 06:37 AM
Hmm, not really sure what your code is supposed to be doing, but I think what I would do is Instantiate the particle emitter upon something penetrating the Collider.
As in:
//The particle Emitter prefab to instantiate
var myParticleEmitr : GameObject;
function OnTriggerEnter (Bullet : Collider) {
if(Bullet.gameObject.tag=="Enemy1"){
var newParticles : GameObject;
newParticles = Instantiate(myParticleEmitr, transform.position, transform.rotation);
}
}
(Sorry, if this isn't what you were after...)
http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
Thanks you helped me a lot! It worked! I only had to change the GameObject to ParticleEmitter in your script and it worked perfectly!
Answer by PotatoOrgyLt · Mar 03, 2012 at 10:36 PM
Thanks, you helped me a lot! It worked! I only had to change the GameObject to ParticleEmitter in your script and it worked perfectly!
Your answer
![](https://koobas.hobune.stream/wayback/20220613064709im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Play particle effect upon animation trigger 1 Answer
Particle emitter to emit "one-shot" on specific occasions 5 Answers
Level Up Particle Effect 1 Answer
Heat Haze Particle System 1 Answer