- Home /
Change particle render material randomly.
Hi thank you for viewing this again :
First I have var splatters = Material[];
Then on collision it calls the following two lines....
splatMaterial = Random.Range(0,splatters.length);
Which works... untill I get to this... PS> The object list I drag for materials 0 - 5 all have a material set it does create this object and it has a child " particle system.... I' m lost...
I have this line of code
gameobject.GetComponentInChildren(ParticleRenderer).renderer.material = splatters[splatMaterial];
//Why Does this not work..... it gives me ERROR :Object reference not set to an instance of an object " NULL "
//There is no null for this line of code game object would replaced with instantiate object I .. never get null when use regular object with material....
Your main object, does it have a child object with the particle renderer or is the particle renderer in the main object hierarchy?
Are you using the Legacy or Shuriken particle system? The Shuriken particle system use ParticleSystemRenderer not a ParticleRenderer.
Answer by Imankit · Feb 25, 2013 at 11:01 AM
Use gameObject.GetComponent(ParticleSystem).renderer.material = splatters[splatMaterial];