- Home /
How to change the colour of particles when colliding with a specific object?
Hi all, I have been trying to get this to work all afternoon and it's driving me crazy. can someone tell me how to alter the colour of particles? I have looked at all the script reference stuff which was not very helpful. Heres what I have got so far:
var laserColourGreen: Color = Color(45.0, 255.0, 0.0, 255.0); var laserColourRed: Color = Color(255.0, 0.0, 0.0, 255.0);
function OnParticleCollision (particle : GameObject) { var laserParticles = particleEmitter.particles; if (particle.gameObject.tag == "Laser") { for (var i = 0; i < laserParticles.Length; i++) { laserParticles[i].color = laserColourRed; } }
else { laserParticles[i].color = laserColourGreen; } particleEmitter.particles = laserParticles; }
This script is attached to the particleEmitter. Any ideas?
Answer by DaveA · Apr 24, 2011 at 08:05 PM
This looks like it should work. http://unity3d.com/support/documentation/ScriptReference/ParticleEmitter-particles.html Are you sure that this function is getting called? Can you add some Debug.Log and/or run in the debugger?
Hmm. I added a print("text") when the laser is supposed to collide but it did not print, so there is obviously some problem there. I also discovered gameobject.tag should have been asteroids, not laser. But changing this did nothing. Very strange
AHA! I have got the collision working properly now by ticking send collision message in the world particle collider component of the laser, but now it slows down to the extreme whenever it collides. Why would this be happening?
AHA again! It was because for some inexplicable reason i had the laser emitter pumping out 8000 particles a second. Sorted. Thanks guys
Answer by tomekkie · Apr 24, 2011 at 06:17 PM
You should probably try to access the renderer>material>shader>color or tint color property.
Basically it depends on particles material; if its none or simple one it should work with color property.
Anyway look at the forum thread:
http://forum.unity3d.com/threads/67725-Adjusting-the-Tint-of-a-Particle-Additive-shader
Your answer
