- Home /
How to change smoothness of a material in scripts?
This is as a script on the maze object in my unity, the same object that has the mazeuv material. I want to change the smoothness (which I investigated and saw it is _glossiness?) to move slightly up as time moves on. Anyone have advice?
private Material mazeuv = Resources.Load("Materials/Materials/mazeuv", typeof(Material)) as Material;
// Update is called once per frame
void Update () {
float glossy = mazeuv.getFloat("_Glossiness");
if(glossy < 1){
glossy = glossy + (0.1 * Time.deltaTime);
}
mazeuv.setFloat("_Glossiness", glossy);
}
Answer by JonPQ · Jun 13, 2017 at 12:55 AM
Try getting the material from the gameobject's renderer instead. but you are doing the right thing trying to set the material's shader's parameter name. Just be aware... changin materials, causes unity to clone the material. you can end up with memory leaks, or not changing quite what you want to. Renderer.material (clones and changes it) or Renderer.SharedMaterial (changes master material) you can also right click and edit the shader code, to make sure you have the correct parameter name.
e.g. mat = gameObject.Renderer.materials[0]; string propertyName = "_time"; mat.SetFloat(propertyName, valueToSend);
Note, if there is more than 1 material on object.... you'll need to find the one you want in the array of materials.
Your answer
Follow this Question
Related Questions
My Build Platform won't change. 0 Answers
Spherical panorama texture with transparent sky 0 Answers
How would I make a character select screen? 0 Answers
Need help with script 1 Answer
How to include js libraries ,.css 0 Answers