I want to match the explosion particles colour to the colour of an object hit (or, in my specific instance, to the colour of the root object of the child hit).
I try this but it doesn’t work:
var instantiatedExplosion : GameObject = Instantiate (impactEffect, contact.point,Quaternion.identity);
instantiatedExplosion.GetComponent(ParticleRenderer).materials[0].color = collision.gameObject.transform.root.renderer.material.color;
(where impactEffect is my explosion prefab)
and if I change it to
instantiatedExplosion.GetComponent(ParticleRenderer).material.color = collision.gameObject.transform.root.renderer.material.color;
it sort of works, in that I get the right colour of particles, but the shader I’m using (which is “Particles/Alpha Blended”) is destroyed and I just get particle billboards (but of the right colour).
The following, however, does work but it’s hardly elegant or economical:
var col = rrr.transform.root.renderer.material.color;
var modifiedColors : Color[ ] = instantiatedExplosion.GetComponent(ParticleAnimator).colorAnimation;
modifiedColors[0] = col;
modifiedColors[1] = col;
modifiedColors[2] = col;
modifiedColors[3] = col;
modifiedColors[4] = col;
instantiatedExplosion.GetComponent(ParticleAnimator).colorAnimation = modifiedColors;
Is there a neater way, —maybe a simple error I’m making in the first couple of lines above? THX.