I am trying to dynamically adjust the alpha value of particles in a particle system in the indie version of [Unity 2.6.1f3].
My C# code to do this is as follows:
Particle[] bits = myParticles.particleEmitter.particles;
for(int itor = 0; itor < bits.Length; itor++){
if(bits[itor].color[3] != closeFrac*maxAlpha){
bits[itor].color = new Color(bits[itor].color[0] ,
bits[itor].color[1], bits[itor].color[2],closeFrac);
}
}
Variables:
“myParticles” is a GameObject with an Ellipsoid Particle Emmitter and Particle Renderer attached.The Particle Animator has been omitted because the RGB values I set on Emit() need to be preserved.
“CloseFrac” is a float between 0 and 1 indicating how transparent I want the particles to be at this given frame based on camera to particle center distance. I have put Debug.Log statements in the program to verify that “closeFrac” is moving between 0 and 1 over the course of the program.
The results:
The particles remain at their starting alpha value regardless of the value of “closeFrac” .
EDIT
Thanks to Eric I have found and fixed the error.
Particle[] bits = myParticles.particleEmitter.particles;
for(int itor = 0; itor < bits.Length; itor++){
if(bits[itor].color[3] != closeFrac*maxAlpha){
bits[itor].color = new Color(bits[itor].color[0] ,
bits[itor].color[1], bits[itor].color[2],closeFrac);
}
}
// added to fix the problem
myParticles.particleEmitter.particles = bits;