make material in code unity code example
Example: how to set material c unity
Renderer rend = GetComponent<Renderer>();
if (rend != null){
rend.material = newMaterialRef;
}
Renderer rend = GetComponent<Renderer>();
if (rend != null){
rend.material = newMaterialRef;
}