I’ve been struggling with scripting and posted a few bitches and moans over the past day, but I think I finally made some progress.
I’ve been trying to change the color of particles in a particle system using a script with no success. I tried adding the following to my particle system but have had no success:
function Update ()
{
gameObject.renderer.material.color = Color.red;
}
However, if I put that script on a mess, it works! So my question, why does this script work on a mesh and not particle system?
when you reference a renderer from the game object, you’re referencing the Mesh Renderer, if it’s specifically the particle system (assuming you’re using the new system) then you need to use reference the renderer from the actual Particle System like
var partSys : ParticleSystem;
function Update ()
{
partSys.renderer.material = Color.red;
}
Hope this helps
Thanks for helping me out with this. I tried plugging in your suggestion and got the error:
BCE0020: An instance of type ‘UnityEngine.Renderer’ is required to access non static member ‘material’.
oh my bad, you can’t change material color with material.color you need to do material.SetColor()
So
partSys.renderer.material.SetColor(“_TintColor”,Color.red)
The string “_TintColor” refers to a specific property in the shader, so you depending on the shader you’re using you may need to change that, but for most particle shaders there is a tint color.