- Home /
Is it possible to attach your own scripts to particle system particles, or add behaviour in other ways?
I'd rather not create a custom system from scratch, so the particle system seemed like a cool way to emit particles with all those options, that have behaviour as well.
They let us change physics related aspects of emitted particles and give us access to the collision function, but I can't seem to find a way to actually specify behaviour (with a script component for example).
A simple example case where I'd use this:
I turn physics on in the particle system. When the particle is created I keep track of when it was created.
Now when it hits some target object I simply read that value. The target object may be moving around so the order of particles hitting/being collected isn't guaranteed.
Answer by WinterboltGames · Oct 23, 2017 at 02:40 PM
Yes, you can! check out this part of this doc (it's a ton of help!)
https://docs.unity3d.com/ScriptReference/ParticleSystem.html
There's a property in the ParticleSystem
called ParticleSystem.main
with it, you can access all (literally all) of the particle system properties and behaviors and change them at runtime!
hope this helps.
So in my example how would I attach a script to each particle generated by the particle system?
Sorry, but I didn't get your question right in the first time do you want to attach a script to Every single particle? kinda crazy if you ask me because i think it's impossible, the method above works with particle systems, not particles themselves.
also, think about the performance impact if you have 5 particle systems each emitting 500 particles/$$anonymous$$ and executing functions at the same time! you might get -100 fps!