- Home /
Change shader property and make all materials using shader change also
Kind of hard to word, but I have a shader and I want to change the float value using another script. When I change the float value of a specific property I want all materials using the shader to change also.
How can I do this? I have looked through the documentation and found nothing.
This is as close as I have gotten, but it only fades the material assigned, not all materials using that shader. In java
snowObject.renderer.sharedMaterial.SetFloat( "_Fade", dynamicSnowFade );
Answer by ScroodgeM · Aug 09, 2012 at 09:19 PM
Object [] renderers = GameObject.FindObjectsOfType(typeof(Renderer)); int i_max = renderers.Length; for (int i = 0; i < i_max; i++) { Material[] materials = ((Renderer)renderers[i]).materials; int j_max = materials.Length; for (int j = 0; j < j_max; j++) { if (materials[i].shader.name == "YOUR SHADER") { materials[i].SetFloat("VALUE NAME", 1.0f); } } }
Thank you for this, is it java or C#. I forgot to state that it was in java, my apologies, hopefully it is.
it's C#. i think it is not so hard to translate it to JS if you write in JS 8)
There are wrong indexes in inside loop. Need to replace i to j.
Your answer
Follow this Question
Related Questions
How can i change detail texture? 1 Answer
Choose color/palette swap? 1 Answer
Shader optimization references, float, half, fixed? 3 Answers
Making all instances of an object glow, and not get affected by post-processing 2 Answers
How can I have the same shader but with different settings on other models 1 Answer