I’m trying to use a fade effect for my menus and I want the whole menu to fade out, the menus is in a container. I tried iterating through the children of the container and changing the alpha value of the materials, but then as it fades you can see an overlap effect when there is more than one object on top of another.
Is there a way to fade a game object and its children together so I don’t get the additive effect when there is more than one object?
with the new UI of Unity simply add a Canvas Group to the container and fade out the alpha of the Canvas Group. The children will also fade out with the parent object.
hi,
well there is pretty simple solution
var FadeSpeed:flaot = 2;
var Fade:boolean = false;
function FadeAll(){
for(var gb:GameObject in gameObject){
gb.renderer.material.color = Mathf.Lerp(1,0,Time.deltaTime * FadeSpeed);
}
//Just in cae if the parent alpha hasnt changed
gameObject.renderer.material.color = Mathf.Lerp(1,0,Time.deltaTime * FadeSpeed);
}
function Update(){
if(Fade)
{
FadeAll();
}
}
Atttach this script to the parnet object and at runtime when you set Fade to true it will automaticall fade
You just need a different shader, specifically one that writes to the depth buffer. Here is an example of that:
1