- Home /
How to set the transparency of an object?
Hi guys. I'm making an android app using Unity and I need your help.
I want to change the transparency of an object. It has some children and each one has more children. Each component has a texture applied and I want to set the transparency of the higher level object. I'm already setting Transparent/Diffuse to the shader.
I made a recursive function to change the transparency of all children:
void setColor(Transform go, float transparency)
{
Color c = new Color(go.renderer.material.color.r, go.renderer.material.color.g, go.renderer.material.color.b,transparency);
foreach (Transform child in go)
{
child.renderer.material.color = new Color(c.r,c.g,c.b,c.a);
setColor(child,transparency);
}
}
The call of the function is:
setColor(getObject(gender,"Skin").transform,transparencyValue);
The access of the object is ok.
I want to maintain the texture I'm applying and just change the alpha of all children.
Why I can't change the transparency? Is it due to the fact that there's a texture applied and I'm changing the color? Is Transparency/Diffuse ok? I've tried to set Transparency/Cutoff/Diffuse and then change the cutoff but nothing happened.
Somebody help me, please. Thanks.