- Home /
Access Material property of ParticleRenderer
does anyone have the syntax of accessing the material.element[0] property of the ParticleRenderer component? This is so I can work with the alpha component to properly fade out the particles..The below doesn't quite cut it (is basically similar to Destroy(gameObject)):
public class Collisions : MonoBehaviour {
private ParticleEmitter pEmitter; public GameObject prefab; private GameObject inst;
private void instParticles() {
if (inst == null) {
inst = (GameObject) Instantiate(prefab, pos, Quaternion.identity);
}
if (inst) {
/*ParticleEmitter pEmitter = inst.GetComponent<ParticleEmitter>( );
if (pEmitter.maxSize >= 0) {
pEmitter.maxSize -= 60 * Time.deltaTime;
}*/
ParticleRenderer pRenderer = inst.GetComponent<ParticleRenderer>( );
if (pRenderer.renderer.material.color.a > 0)
pRenderer.renderer.material.color = new Color(
pRenderer.renderer.material.color.r,
pRenderer.renderer.material.color.g,
pRenderer.renderer.material.color.b,
pRenderer.renderer.material.color.a - 0.20f * Time.deltaTime
);
else {
Destroy(inst, 0.175f);
Destroy(go);
pRenderer.renderer.material.color = new Color(
pRenderer.renderer.material.color.r,
pRenderer.renderer.material.color.g,
pRenderer.renderer.material.color.b,
1);
}
//...
Answer by Jessy · Jan 17, 2011 at 05:27 AM
It won't work because none of the particle shaders have a property called "_Color". Either edit the shader, or use SetColor instead.
In addition, there's no reason to use pRenderer.renderer. pRenderer already inherits from renderer; you don't need to fetch the renderer component that's attached to its game object, because it already is that.
http://unity3d.com/support/documentation/ScriptReference/Material-color.html
Your answer
Follow this Question
Related Questions
Optimize code changing transparency of large number of Objects 0 Answers
Alpha-test VS Alpha-blend shader 1 Answer
Numbers in a path? 1 Answer
Changing material alpha under runtime 1 Answer
Tinted alpha 1 Answer