How does one change the Material of an object?

This is beyond confusing. Is there a simple way to assign an existing material to an object on an event from your Materials folder, then switch it back out after that event has taken place? Like CSS for link and hover.

something like this, (pretending we have two materials in the Materials folder, one already assigned to the object (normal01) and another called “ouch01”, who isn’t assigned to anything in particular but we want him to come and switch out “normal01” for a little bit to indicate something happened):

if ( some kind of event )
{
	renderer.sharedMaterial = ouch01;
	yield new WaitForSeconds (0.5);
	renderer.sharedMaterial = normal01;
}

How would one make the above magic work?

Hey man, I’d setup the materials in inspector eg:

var ouchMaterial : Material;

function Update(){

   if (some event){
	changeMaterial();
	}

}

function changeMaterial(){
	var normalMaterial : Material = renderer.material;

	renderer.material = ouchMaterial;

	yield WaitForSeconds (0.5);

	renderer.material = normalMaterial;

}

Thats perfect, thank you!

I added var normalMaterial : Material; to the mix, but I guess it should be in there anyway.