- Home /
Activating a particle emitter whith onTriggerEnter ?
Hi,
If i just made a box collider in an area in my game (that is a forest) and when the player enters the collider , how to activate the leaves particle emitter ?
I have a leaf particle emiteer and i have this script but it isn't working
============
var particles : GameObject; function OnTriggerEnter(other : Collider){
if(other.gameObject.CompareTag("player")){
particles.emit = true;
}
}
================
I prefer to script in Javascript.
Answer by TurboHermit · Apr 12, 2012 at 08:35 PM
Should look something like this.
var PartEmit : ParticleEmitter; function OnTriggerEnter (other : Collider) { PartEmit.particleEmitter.emit = true; }
Haven't tested it though.
should i put the script on the collider or the particle emitter ?
Answer by GC1983 · Apr 12, 2012 at 08:21 PM
If you haven't done so, try making the P in particle lowercase; particleEmitter.
no it's good that way , monodevelop highlights it in blue and when setting the p in lowercase unity doesn't find it.
Answer by john-essy · Apr 12, 2012 at 11:06 PM
var particles : GameObject
if(other.gameObject.tag == ("player"))
{
particles.enabled = true;
}
else
{
particles.enabled = false;
}
Answer by TheFrankman123 · Apr 13, 2012 at 11:51 AM
try 'FindWithTag' instead.
and your variable should be 'var particles : ParticleEmitter;' so it's as follows:
var particles : ParticleEmitter;
function OnTriggerEnter (other : Collider) {
if(other.gameObject.FindWithTag("player")) {
particles.emit = true;
} else {
particles.emit = false;
}
}
Make sure you accept the answers that helped you.
Also unless you have written your own tag the the tag will be "Player" with a capital P.
thanks for the answer i will see if this works. About the capital P in the script it is player , but i changed it in the script already to a P.
still no luck.
i'm going to look for other questions with the same thing.
But everyone thanks for the help !
This answer IS correct. Have you made the particle emitter a child of the object the script is attached to? and have you dragged the particle emitter onto the public variable in the inspector?
The emitter is a child of a character controller so it follows the character, and it is assigned at the script variable in the inspector,the thing is when this character hit the box collider that surrounds the forest it needs to start emiting some leafs at the position of the character so it is a child of it.
Your answer
Follow this Question
Related Questions
How to make windswept snow on mountains? 0 Answers
How to pause emitter in new Particle System? 2 Answers
Modifying particle renderer material and assigning new particle emmitter 1 Answer
Accessing Particle emitter 0 Answers
ARK of the COVENANT | How do I trigger Particles to come out once the top has been removed? 0 Answers