- Home /
Change particles alpha / sharedMaterial
I have two different issues with particles and I have trouble in both of them.
First issue - dissolve a particle
I have a particle effect that is a gameobject group that consists of 4 different legacy particle systems (emitter+animator+renderer). I need to smoothly dissolve it using opacity.
First thing I do is I stop all emmitters. And that works ok.
 for (var c: Component in fx.GetComponentsInChildren(ParticleEmitter)) {
     var pe: ParticleEmitter = c as ParticleEmitter;
     pe.emit = false;
 }
But then I'm trying to affect the alpha of emitted particles and that's where I fail:
 for (var c: Component in fx.GetComponentsInChildren(ParticleEmitter)) {
     // I've tried trough particle emitter:
     var pe: ParticleEmitter = c as ParticleEmitter;
     var pr: Particle[] = pe.particles;
     for (var i: int = 0; i < pr.Length; i++) {
         pr[i].color.a = new_alpha;
     }
     
     // I've also tried through particle animator:
     var pa: ParticleAnimator = c as ParticleAnimator;
     for (var i: int = 0; i < pa.colorAnimation.Length; i++) {
         pa.colorAnimation[i].a = new_alpha;
     }
 }
So, I need to change alpha of emitted legacy particles and don't know how to do that.
Second issue - shared particle material
This is not connected to 1st issue. Here are different particles.
So, I have a bunch of particles that use the same material. And when I'm running my game in editor and use inspector to change that material's color - it works fine and affects on all particles on the screen.
But I can't to do that using code.
I've tried to get a shared material from one of my particles and to change it:
 var material: Material =
     particle_go[0].GetComponentInChildren(ParticleSystem).renderer.sharedMaterial;
 // material is not null here!
 material.color = new_color;
How do I change the shared material just as I do when changing "color" property in inspector?
Your answer
 
 
             Follow this Question
Related Questions
How to destroy live particle in Shuriken 1 Answer
How is Limit Velocity Over Lifetime calculated? 0 Answers
Tutorial for Jean Moreno's Cartoon FX?? 1 Answer
Scale Shuriken Particle System with Parent Transform 5 Answers
Particle Playback Error in 5.4 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                