- Home /
Change Shader Property at runtime
Hello community. Have a object with "Toon/Basic Outline" Shader.
The properties of this shader is
Properties {
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
}
And in my script I want to change the "Outline Color" property at runtime.
I have tried:
renderer.material.setColor("Outline Color", Color.red);
But I cannot get it to change.
[SOLVED] Solution was to write _OutlineColor and not "Outling Color". I also discovered that I could not use my own Color ( example: new Color(1,1,1,1)), I had to use build in colors( example: Color.red)
Answer by Berenger · Apr 10, 2014 at 09:26 AM
First parameter is the name of the variable, not the label .
renderer.material.setColor("_OutlineColor", Color.red);
These days in Unity:
gameObject.GetComponent<Renderer>().sharedMaterial.SetFloat("_YourParameter", someValue);
Thank you. Do you know if I can make my own Color ins$$anonymous$$d of using Color.someColor?
Answer by Shivam_Dhoot · Oct 01, 2014 at 05:57 AM
`renderer.material.setColor("_OutlineColor",new Vector4(a,b,c,d));`
a,b,c,d will be red,green,blue and alpha values for your color.
These days in Unity:
gameObject.GetComponent<Renderer>().sharedMaterial.SetFloat("_YourParameter", someValue);
You can also use the following ins$$anonymous$$d of a Vector4.
new Color32(127, 127, 127, 255)
Your answer
Follow this Question
Related Questions
Using Color.Lerp with Lightweight Render Pipeline 1 Answer
Colors does not aplying to particle system with mesh render mode + material with standard shader. 2 Answers
Simple Color Shader for 3D Models 0 Answers
Can anyone solve this?Build/Material/Shader/Android/Quality 0 Answers
How Do I Partially Change The Material of An Object On Collision? 1 Answer