Reputation: 313
How can I change the color of the particle system to be same as my player color?
I tried to find on some tutorials how to do it and I got this solution:
GameObject effectBlow = Instantiate(blowOut, transform.position, Quaternion.identity) as GameObject;
effectBlow.gameObject.GetComponent<ParticleSystem>().startColor = material.material.color;
But now my Unity is complaining about that code and it says it's obsolete and of course colors don't change in game.
I don't know how to change it, can somebody help me ?
Upvotes: 3
Views: 9471
Reputation: 7220
startColor property is deprecated,so it can't be used like that, try this code
GameObject effectBlow = Instantiate(blowOut, transform.position, Quaternion.identity) as GameObject;
var main = effectBlow.gameObject.GetComponent<ParticleSystem>().main;
main.startColor = player.GetComponent<Renderer>().material.color;
So what it basically does is it create a variable main and the instantiated gameobject's particleSystem main module will be refereed to it from that main variable we use startColor property to modify the color of player gameobject
For more info check this out : https://docs.unity3d.com/ScriptReference/ParticleSystem-main.html
Upvotes: 3