I want to create a particle(prefab) and use another object color to change those particle's color but it seems everything is changed and I don't know the new method to use it.

Here my code:

 GameObject breakpart = Instantiate (smoke, gameObject.transform.position , Quaternion.identity) as GameObject;     

 breakpart.GetComponent<ParticleSystem>().startColor = gameObject.GetComponent<SpriteRenderer>().color;

So how can I fix it?


Particle Systems in Unity have modules to keep various bits of related data together. The start color is in the Main module.

Set the startColor property:

var ps = breakpart.GetComponent<ParticleSystem>();
var main = ps.main;
main.startColor = gameObject.GetComponent<SpriteRenderer>().color;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.