标准着色器将从" Opaque"到"透明"在运行时但不会显示任何更改。为什么?

时间:2017-08-26 07:35:45

标签: c# unity3d shader

当我点击检查器中的下拉框时它会改变,但在实际游戏中它毫无价值。我猜我需要在我的代码中做一些事情来刷新"着色器,但我无法弄清楚它是什么。

public void MakeMaterialsTransparent () {

    // get all of the materials in an array
    Material[] materials = gameObject.GetComponent<Renderer>().materials;
    Material[] newMats = new Material[materials.Length];
    for (int i=0; i<materials.Length; i++) {

        // copy the material
        newMats[i] = new Material(materials[i]);

        // set alpha for transparency
        newMats[i].color = new Color(newMats[i].color.r, newMats[i].color.g, newMats[i].color.b, 0.78f);

        // This SHOULD change the material to transparent
        // but it only works when I look at it in the inspector
        newMats[i].SetFloat("_Mode", 3);

    }

    // set the materials to the new array
    gameObject.GetComponent<Renderer>().materials = newMats;
}

0 个答案:

没有答案