How do I change the renderer material ?

I want to switch the renderer material during runtime.

I’ve tried googling, reading class docs… I’m sure that this has been asked and answered, but I can’t find it…

The most that I can get to happen is creating a material with the name of “Specular”, with a shader with the name of “Specular”, instead of the material “DoorSwing_unsecure” from the Assets/Materials folder, which does exist.

This is so frustrating right now!

void Update()
{
	if(onetime == 0)
	{
		onetime = 1;

		string textName = "DoorSwing_unsecure";
		Material newMat = new Material(Shader.Find("Specular"));
		Texture newTex = Resources.Load(textName) as Texture2D;

		newMat.mainTexture = newTex;
		renderer.material = newMat;
	}
}

Please help me, I’m sure that this just so simple that it’s “stupid simple”, but I just can’t figure it out.

Thanks

[35756-screen+shot+2014-11-24+at+5.31.11+pm.png|35756]

If DoorSwing_unsecure is an existing material, I’d do this: (and then drag “DoorSwing_unsecure” from the Assets/Materials folder into the newMat slot of this script in the inspector)

public Material newMat;

void Update()
{
  if(onetime == 0) {
    onetime = 1;
    renderer.material = newMat;
  }
}