- Home /
Use particles as Trigger (Shuriken)
Hi guys,
is it possible to use a particle (or multiple) as a kind of trigger System? I've got a shuriken that emits particles on KeyInput which then fall down due to gravity. Everything fine here. But I want to change some properties of other Gameobjects (like position...) when the particles reach a specific height. But dont stop them from falling as it happens when I use a Collider... I hope my question ist clear? I have no idea right now :/
Answer by OllyNicholson · Feb 06, 2014 at 02:58 PM
You can use the newly implemented 'particle callbacks' as demonstrated here:
http://blogs.unity3d.com/2013/07/22/unity-4-2-has-arrived/
You can write a script to attach to the 'colidee' that would detect when a particle has collided, the documentation for that is here:
http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem.GetCollisionEvents.html http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnParticleCollision.html
The collision itself was not the problem, but it stops the particles and they get stuck. I solve the problem by checking the position of each particle and if they reached a certain level is fired a custom event.
Now it looks similar to this:
ParticleSystem.Particle[] p = new ParticleSystem.Particle[t.gameObject.particleSystem.particleCount];
int pSize = t.gameObject.particleSystem.GetParticles(p);
if(pSize <= 0 || _triggerFlag) { return; }
for(int i = 0; i < pSize; i++) {
if(p[i].position.z >= 5.0f && !_triggerFlag) {
// Fire event
}
Answer by Kevz93 · Jul 24, 2017 at 02:46 PM
Use onParticleTrigger(). I think this would be more suitable to your case. https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleTrigger.html