How do I access a different material via Javascript?

Hi,

Sorry for the Newbie question!

I’m stuck on something really simple. I can’t seem to change materials on an object. I’m trying ot change between the below materials on keypress “G”. Both materials are in my materials folder, but l can’t seem to get the script to load the “TestButtonOn” material, …

Materials, …
TestButtonOff (already assigned)
TestButtonOn

Code, …

   function Update () 
   		{
   		var newTexture : Texture;
		newTexture = Resources.Load("TestButtonOn");
        
   		if(Input.GetKeyDown(KeyCode.G))
        	{
                renderer.material.mainTexture = newTexture;
        	}
       		if(Input.GetKeyDown(KeyCode.B))
        	{
            	print ("My Texture is " + newTexture.name);
            }
        }

Cheers

i dont know if that will work, but you can try

newTexture = Resources.Load("TestButtonOn", Texture);

as the Resources.Load receives 2 params, the path of the image and the type to be cast.