- Home /
How to manage shader with script
How can I change Standard to Standard(Specular setup) with script? Pls tell me...
Thank you
スクリーンショット-2017-12-03-200818.png
(16.7 kB)
Comment
Answer by sethuraj · Dec 04, 2017 at 09:24 AM
Yes, you can change the material shader at runtime, here is a way to do it. (Assuming the gameobject to which the script is attached has a mesh renderer component)
void SetSpecularShader()
{
//Get the mesh renderer
MeshRenderer m_Renderer = GetComponent<MeshRenderer>();
//Get the specular shader
Shader m_StandardSpecular = Shader.Find("Standard (Specular setup)");
//Apply the shader
if (m_StandardSpecular)
m_Renderer.material.shader = m_StandardSpecular;
else
Debug.Log("Check shader name");
//Assign shader values....
}
Hope this helps...
Your answer
![](https://koobas.hobune.stream/wayback/20220612143854im_/https://answers.unity.com/themes/thub/images/avi.jpg)