Changing textures on multiple materials shared by a mesh renderer

Hello. I am working on a project and using JavaScript to change the main textures on materials at the push of a GUI button (renderer.material.mainTexture= whatever). I’ve been keeping it really simple and so far, things have been moving along perfectly and without any trouble.

However, I just encountered a mesh renderer on a single mesh that is using two separate materials. I apply my texture switcher script and just as I expected, it is only switching the texture on one of the two materials.

I’m attaching the script I am using as well as a screen grab of my inspector. Again, this is working perfectly on everything else except the mesh with 2 materials. Is there a way to change the texture on that second material?

var RaceRedTexture:Texture;
var SilverMetallicTexture:Texture;
var DarkBlueTexture:Texture;
var FrozenWhiteTexture:Texture;
var PantherBlackTexture:Texture;
var TectonicSilverTexture:Texture;
var SchoolbusYellowTexture:Texture;
var MidnightSkyTexture:Texture;
var BurnishedGlowTexture:Texture;
var SolarYellowTexture:Texture;
var DeepImpactBlueTexture:Texture;

function AssignColor (chg:int)

{
switch(chg)
{
case 1:// Race Red
gameObject.renderer.material.mainTexture=RaceRedTexture;
break;

	case 2:// Silver Metallic
	gameObject.renderer.material.mainTexture=SilverMetallicTexture;
	break;
	
	case 3:// Dark Blue
	gameObject.renderer.material.mainTexture=DarkBlueTexture;
	break;
	
	case 4:// Frozen White
	gameObject.renderer.material.mainTexture=FrozenWhiteTexture;
	break;
	
	case 5:// Panther Black
	gameObject.renderer.material.mainTexture=PantherBlackTexture;
	break;
	
	case 6:// Tectonic Silver
	gameObject.renderer.material.mainTexture=TectonicSilverTexture;
	break;
	
	case 7:// Schoolbus Yella
	gameObject.renderer.material.mainTexture=SchoolbusYellowTexture;
	break;
	
	case 8:// Midnight Sky
	gameObject.renderer.material.mainTexture=MidnightSkyTexture;
	break;
	
	case 9:// Burnished Glow
	gameObject.renderer.material.mainTexture=BurnishedGlowTexture;
	break;
	
	case 10:// Solar Yellow
	gameObject.renderer.material.mainTexture=SolarYellowTexture;
	break;
	
	case 11:// Deep Impact Blue
	gameObject.renderer.material.mainTexture=DeepImpactBlueTexture;
	break;
}

}

[20116-screen+shot+2014-01-02+at+2.52.20+pm.png|20116]

I answered my own question. It took some digging to find but it was super simple. Multiple materials on a mesh are handled in Unity as an array. Here’s the solution for anyone who needs it: (I’m just posting a small chunk of my code.)

function AssignColor (chg:int)

{

switch(chg)
{
	case 1:// Race Red
	gameObject.renderer.materials[0].mainTexture=RaceRedTexture1;
	gameObject.renderer.materials[1].mainTexture=RaceRedTexture2;
            break;
    }

}