设置所有材质的纹理

时间:2021-02-12 14:29:48

标签: c# unity3d

如何从游戏对象中获取所有材质(有些有 5-10 个材质)并为这些材质中的每一个设置相同的纹理?

public GameObject go;
public Texture texture;
void Start()
{
 go.GetComponent<Renderer>().material.SetTexture("_BaseMap", texture);
}

2 个答案:

答案 0 :(得分:1)

我有办法做到这一点。通过将所有材料放入一个数组中。


 Material[] myMaterials = gameObject.GetComponent<Renderer> ().materials;
        for (int i = 0; i < myMaterials.Length; i++) {
            myMaterials[i].SetTexture ("_BaseColorMap", texture);
        }

答案 1 :(得分:-1)

公共游戏对象 go,go1,go2; 试试这个方法