change a texture of a specified material.

Hi,

I’m sure it’s stupid, but I can’t manage to work this out.

I’ve got and object with 3 different materials, a gui button and 2 textures.

I want to switch the diffuse texture of the second material between my two textures every time I click.

Everything is set up except I don’t know how to select the second material…

I can"t find it in the script ref :frowning:

    public static bool T = true;
    public Material Ground;
    public Texture Real;
    public Texture Map;
    private Texture textureAlpha;
        if (T == true) {
            textureAlpha = Real;
            
        }
        else if (T == false) {
            textureAlpha = Map;
            
        }

       

        renderer.material.SetTexture("_MainTex", textureAlpha);

This script works for an object with one material.

Thank’s for the help

Boobi

Warning: Not tested

renderer.materials [0].SetTexture("_MainTex", textureForMaterial0);
renderer.materials [1].SetTexture("_MainTex", textureForMaterial1);
renderer.materials [2].SetTexture("_MainTex", textureForMaterial2);

Nice one, I was trying materials[1] = material.setTexture… ^^

Cheers