Hello. I’m creating a game, and at one point in the game, all objects in the screen fade out. To do this, I’m using a loop to assign all objects a temporary transparency shader, then turning down the alpha property. It seems to work perfectly when I’m inside the Unity Editor. However, if I try to build an executable and run it, all the objects turn pink when they are supposed to be fading away. I know this means that it can’t find the correct materials, but they’re all in the project, so I assume it is a problem with Unity finding the shaders. To clarify, I’m creating Shader variables, then assigning them in the Start function. Thanks in advance for the help. Code below:
Shader shaderTrans;
void Start () {
shaderTrans = Shader.Find ("Transparent/Diffuse");
shaderIlluminate = Shader.Find ("Self-Illumin/Diffuse");
}
void Update () {
objList = GameObject.FindObjectsOfType (typeof (GameObject));
foreach(GameObject obj in objList){
if(obj.renderer){
foreach (Material mat in obj.renderer.materials){
mat.shader = shaderTrans;
Color oldColor = mat.color;
mat.color = new Color(oldColor.r,oldColor.g, oldColor.b, alphaFade);
}
}
}
}