unity set material

C#
gameObject.GetComponent<Renderer>().material = newMaterial;
Source

Also in C#: