- Home /
Metallic/Specular map broke fading in build
When enemies die in my game they fade instead of just disappearing and it works fine until my character have metallic/specular map attached to it. I can change values without map (for whole material) and it works good, but when i put any metallic/specular map it doesn't work anymore (shader is still switching to Fade but alpha is not changing at all). Also, it ONLY happens in build, it works fine in editor. How can i fix this?
Here is my code responsible for changing material from Opaque to Fade:
Material m = GetComponent<SkinnedMeshRenderer> ().material;
m.SetFloat ("_Mode", 2f);
m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
m.SetInt("_ZWrite", 0);
m.DisableKeyword("_ALPHATEST_ON");
m.EnableKeyword("_ALPHABLEND_ON");
m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
m.renderQueue = 3000;
readyToFade = true;
Here is a part responsible for actual fading (it's in Update):
if (readyToFade)
{
Material m = GetComponent<SkinnedMeshRenderer> ().material;
float alpha = m.color.a;
Color color = new Color (1, 1, 1, 1);
if (alpha - Time.deltaTime <= 0)
alpha = 0;
else
alpha -= Time.deltaTime;
color.a = alpha;
m.color = color;
if (alpha == 0)
Destroy (gameObject);
}
Comment