set material unity script code example
Example 1: c# change material in code
currentObject.GetComponent<Renderer>().material = materialToAssign;
Example 2: unity set material
gameObject.GetComponent<Renderer>().material = newMaterial;
currentObject.GetComponent<Renderer>().material = materialToAssign;
gameObject.GetComponent<Renderer>().material = newMaterial;