Hi there,
I’m currently having problems with Unity’s builtin default cutout shader. Every time I make an object (that has this shader on it) invisible and then visible again by changing the alpha channel of the material’s color, the transparent parts of the object become opaque.
Does anybody know why this happens and how I can avoid it?
My Code (Ignore the thin with the irgnorationVector):
private Renderer rend;
private void Start()
{
rend = this.GetComponent<Renderer>();
ownCollider = this.GetComponent<Collider>();
}
//gets called by another script
public void handleTransparency(Transform mainCamera)
{
if (ignorationVector == Vector3.zero || !Vector3Helper.checkIfCollinear(mainCamera.forward, ignorationVector))
{
setTransparency(0f);
}
else
{
setTransparency(255f);
}
}
public void setTransparency(float alpha)
{
if(rend == null)
{
return;
}
if(alpha > 255)
{
alpha = 255;
}
if(alpha < 0)
{
alpha = 0;
}
Color color = rend.material.color;
color.a = alpha;
rend.material.color = color;
}
Before:
After: