Floating GUI button to change correct material of character

I have a script which keeps a floating GUI button over a character. Whenever the button is touched it activates a change in material.The only problem is that if my character is imported as a single mesh with five different materials I can only get the button to affect material element 0. If I want it to affect material element 3, how do I get it to do that ? I am not sure how to change the element order.

My script is like this:

var materials : Material[];

var buttonTexture : Texture; //The texture to use on the button
var offset = Vector3.up; //World space offset. 1 unit above object by default
var clampToScreen = false; //Will the label be visible if object is off screen
var clampBorderSize = .05; //screen space to leave when clamped
var useMainCamera = true; //Use the camera tagged MainCamera
var cameraToUse : Camera; //Camera to use if useMainCamera is false
private var cam : Camera; //The camera we're using
private var screenPos : Vector3; //The screen position of the button

function Start () {
    if(useMainCamera) cam = Camera.main;
    else cam = cameraToUse;
}

function Update () {
    if(clampToScreen) {
        var relativePosition = cam.transform.InverseTransformPoint(transform.position);
        relativePosition.z = Mathf.Max(relativePosition.z, 1.0);
        screenPos= cam.WorldToScreenPoint(cam.transform.TransformPoint(relativePosition + offset));
        screenPos= Vector3(Mathf.Clamp(screenPos.x, clampBorderSize,Screen.width-(clampBorderSize+buttonTexture.width)),
                                    Mathf.Clamp(screenPos.y, clampBorderSize,Screen.height-(clampBorderSize+buttonTexture.height)),
                                    screenPos.z);
    }
    else screenPos= cam.WorldToScreenPoint(transform.position + offset);
}

function OnGUI() {
    if(GUI.Button(Rect(screenPos.x,Screen.height - screenPos.y,buttonTexture.width,buttonTexture.height),buttonTexture))

        renderer.material = materials[Random.Range(0,materials.length)];

}

You can use:

renderer.materials
*```*
*<p>where i is the number material you want to affect. You can use a loop with <strong>renderer.materials.length</strong> to go through all materials.</p>*

Yeah, I dont know, its weird ... I can see that it should be a simple fix but it is not working for some reason. I have done it just like you say replacing renderer.material with renderer.materials[3] and it doesnt change the material. I can see that it is registering the click though.The original script works fine on a character which has the changeable skin as element 0. But the next character, the skin has come in as element 3 and the eyeballs are element 0, so it make sense to change the script in this way, but it is not doing anything for some reason. In the inspector with the original you can see when the individual materials are changing , but in this case, with the renderer.materials[3], they dont change, though I can see that they are reading the click, as "instanced "comes up next to the material when clicked.weird.

I have the same problem…Please help!