- Home /
Cannot change material on build
void FadeTransparentMaterial(Renderer selectedRenderer)
{
foreach(Material material in selectedRenderer.materials)
{
material.SetFloat("_Mode", 2);
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = 3000;
}
}
void FadeBack(Renderer renderer)
{
foreach(Material material in renderer.materials)
{
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = -1;
}
}
This code makes material transparent and opaque on runtime, but IT DOESNT WORK in build mode. Build zip included. Shaders:standard.
Code is executed if something covers player, so if you use build go inside of the small building and you will see that it is not working
Functionality works just perfectly in editor's playmode if that's the question
Forgot that I also use Itween fade to. It works fine in editor but not in build
Answer by conguerror · Mar 04, 2021 at 09:51 PM
create empty object with fade type materials or transparent type materials(you can do both)
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
How to change a value in custom shader through script, C# 1 Answer
How to find and assign Default-Particle material to a renderer 2 Answers
materials turn pink after changing render pipeline asset 4 Answers
Only on Mac OSX: Rendering/shader error within webplayer 0 Answers