- Home /
Change material color at runtime!!
I wonna change the color of the material at the runtime (particle system)!
var partColor : GameObject;
function Update(){
if (Input.GetButton ("Jump")) {
partColor.renderer.material.color = Color.red;
}
}
Why doesnt it work? What am i doing wrong?
Celofa
Answer by efge · Jan 18, 2011 at 09:41 AM
The color of a particle can be modyfied by Particle.color.
var partColor : Color; function Update () { partColor.particle.color = Color.red; }
like that?? sry iam really new to Unity?
Answer by Noah-1 · Jan 18, 2011 at 07:28 PM
Hello, well try this piece of code:
function Start () {
// Set glossy shader so that specular color is used renderer.material.shader = Shader.Find (" Glossy");
// Set red specular highlights
renderer.material.SetColor ("_SpecColor", Color.red); }
Answer by Dylan Fitterer · Jan 18, 2011 at 09:36 PM
MaterialPropertyBlock might be what you're looking for: http://unity3d.com/support/documentation/ScriptReference/MaterialPropertyBlock.html
With it, meshes using the same material can be different colors.
Answer by m4a4 · Feb 19, 2012 at 01:15 AM
YourParticleTransform.GetComponent().material.SetColor("_TintColor", DesiredColour); Works if you are using Particle Materials
Answer by DaveA · Feb 19, 2012 at 03:18 AM
You could also try this: http://answers.unity3d.com/search.html?redirect=search%2Fsearch&q=change+color+on+particles