- Home /
Set Color not working on Outline
Hey Guys,
I'm trying to change the outline color of a shader based on the characters health. So when the character has high health, his outline is green, but as it gets closer to 0, it turns more and more red.
My problem is I can't seem to find a way to change the color of the outline. I think I need to use "Material.SetColor", but it's not effecting the outline color at all. Here is the line I'm trying to use (c#):
thisRenderer.material.SetColor("_OutlineColor", Color.red);
I'm just using a Color.Lerp based on the character's health to switch between the colors for low and high health. The name of the property in the shader file is "_OutlineColor", so that's what I need to change, right?
To test this, I make the material's color outside of play mode cyan. Then I put this line of code inside the Update function. So what should happen is the character's color will change to red every frame. However, when I go into play mode, the character's color stays cyan. What's happening?
Thanks for the help. (Shader file here: http://wiki.unity3d.com/index.php?title=Silhouette-Outlined_Diffuse)
Your code works for me. I used:
function Start() {
renderer.material.SetColor("_OutlineColor", Color.blue);
}
...with the shader you specified, and the color changed. Are you sure that 'thisRenderer' points to the renderer with a material that has the outline shader?
renderer.material only works if the renderer has only one material, otherwise you have to use renderer.materials and iterate through each one. Also, check that _Outlinecolor is indeed the right name of the color variable in the shader script.
I'm pretty sure thisRenderer is right. I use it other places to change the material. I can change from a diffuse to an outline diffuse, but it won't let me change color.
And I'm pretty sure "_OutlineColor" is the right variable name. What else could it be.
I'd do a test scene with a cube, a material with this shader, and my short script. Works or not, it will tell you something. Also did you read @Cherno's comment? If your object has multiple materials, then you need to cycle through all the materials in the materials array, not just 'material'.
thisRenderer only has one material. I change the material manually through scripting.
Your answer
Follow this Question
Related Questions
Shader Assitance: Sprite Outline Color, Hidden Object -1 Answers
Modified Toon Shader: scaled instead of projected (how to?) 0 Answers
Ztest shader issues 0 Answers
Outline diffuse shader (toon) : no results? 1 Answer
Better Outlines 0 Answers