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