I have made a system that detects all objects that are in-between the camera and gives them transparent properties when they are not gives back their normal ones, it works like a charm in the editor but when I build the project transparency stops working.
Here’s the script that turns them transparent:
foreach (var mat in a.renderer.materials)
{
mat.SetFloat("_Mode", 3);
mat.SetColor("_Color", new Color(mat.color.r, mat.color.g, mat.color.b, 0.3f));
mat.renderQueue = 3000;
mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
mat.SetInt("_ZWrite", 0);
mat.DisableKeyword("_ALPHATEST_ON");
mat.EnableKeyword("_ALPHABLEND_ON");
mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
}
and this one turns them back into opaque:
foreach (var mat in a.renderer.materials)
{
mat.SetFloat("_Mode", 0);
mat.SetColor("_Color", new Color(mat.color.r, mat.color.g, mat.color.b, 1f));
mat.renderQueue = 2000;
mat.SetInt("_SrcBlend", 1);
mat.SetInt("_DstBlend", 0);
mat.SetInt("_ZWrite", 1);
mat.EnableKeyword("_ALPHATEST_ON");
mat.DisableKeyword("_ALPHABLEND_ON");
mat.EnableKeyword("_ALPHAPREMULTIPLY_ON");
}
I’m not familiar with materials and shaders so all help will be appreciated