How to change the specific material of a Polymesh which has 7 different materials on it?

Hello there!

On that polymesh i have the script attached which should change a texture (material) if the player win the level in the area of the winning zone.

The player script is checking if it collide with the winning zone and i am getting the information to the other script on that polymesh of the level.

i tried with foreach but i deleted it, because it doesnt worked. (Maybe i use it wrong i think?)
The only material i was able to change was the first one.

How can i get to the solution to change the 5. material of the polymesh?

You should do it in some way similar to this:
using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

    public Material material5th;

	void changeMaterial () {
        Renderer r = GetComponent<Renderer>();
        Material[] mats = r.materials;
        if(mats.Length>4) mats[4] = material5th;
        r.materials = mats;