c# change material in code

C#
currentObject.GetComponent<Renderer>().material = materialToAssign;
Source

Also in C#: