Change sub-material of an object?

Hello. I have been searching for this for perhaps two hours now, but nothing appears to work. I have three rooms, and I already have a code so that the player could move forever along them. But how can I change the sub-material of the wall and of the floor randomly? I have 4 floor variations, and 8 wall variations, but I can’t get the thing to change properly. Any help would be appreciated.

Here is my code:

var room = 1;
var inroom = 1;
var roomfront : Transform;
var roommed : Transform;
var roomback : Transform;
var piano : Transform;
var maincamera : Transform;
var walltexture: Material [];
var walltexturetwo: Material [];


roommed.renderer.materials [0]= walltexture[Random.Range(0, walltexture.Length)];
roommed.renderer.materials [2]= walltexturetwo[Random.Range(0, walltexturetwo.Length)];

function Update () 


{if (Input.GetKeyDown("space") && inroom == 1) 
{
roomfront.renderer.materials [0] = walltexture[Random.Range(0, walltexture.Length)];
roommed.renderer.materials [2]= walltexturetwo[Random.Range(0, walltexturetwo.Length)];
roomback.position = Vector3 (-29.91534, 9.142463, (-94.81549));
maincamera.position = Vector3 (-25.54817, 14.8314, (-72.66501 + 7.72372));
piano.position = Vector3 (-32.32533, 10.93454, -72.66501);
inroom = 2;
}

else if (Input.GetKeyDown ("space") && inroom == 2) {
 roomback.renderer.materials [0]= walltexture[Random.Range(0, walltexture.Length)];
 roommed.renderer.materials [2]= walltexturetwo[Random.Range(0, walltexturetwo.Length)];
maincamera.position = Vector3 (-25.54817, 14.8314, (-94.81549 + 7.72372));
piano.position = Vector3 (-32.32533, 10.93454, (-94.81549));
roommed.position = Vector3 (-29.91534, 9.142463, (-116.96597));
inroom = 3;
	}
	
else if (Input.GetKeyDown("space") && inroom == 3){
 roommed.renderer.materials [0]= walltexture[Random.Range(0, walltexture.Length)];
 roommed.renderer.materials [2]= walltexturetwo[Random.Range(0, walltexturetwo.Length)];
maincamera.position = Vector3 (-25.54817, 14.8314, (-50.51353 + 7.72372));
roomfront.position = Vector3 (-29.91534, 9.142463, -72.66501);	
roommed.position = Vector3 (-29.91534, 9.142463, -50.51353);
roomback.position = Vector3 (-29.91534, 9.142463, -28.36128);
piano.position = Vector3 (-32.32533, 10.93454, -50.51353);
inroom = 1;
}

}

So, um, anyone?