unity assign material in code code example
Example 1: c# change material in code
currentObject.GetComponent<Renderer>().material = materialToAssign;
Example 2: how to set material c unity
Renderer rend = GetComponent<Renderer>();
if (rend != null){
rend.material = newMaterialRef;
}