I want a GameObject like the cube do fade in or fade out when I want it to.
With fading in and out I mean that the Object seems to disappear and slowly becomes invisible.
I know that if I want to make an Object invisible I can do gameObject.SetActive(false). But I want it to be animated.
I also tried changing the Renderers alph over time. That works but doesn´t look good. And even if the object is fully transparent you can still see it.
So I thought about creating a transparent wall that somehow hides the Object. So that you don´t see the wall and you don´t see the gameObject. I don´t know if this is even possible.
Does anyone have a better aproach about doing this? Or do you have any idea on how I would realize my idea?
Thanks in advance!
This is a basic Standard Surface Shader. I modified a bit so you can change the visibitily.
All you need to do is make a script that changes the _Visibility value.
bool FadeIn() {
float val = Mathf.Lerp (0, 1, t);
t += speed * Time.deltaTime;
renderer.material.SetFloat ("_Visibility", val);
return t > 1;
}
If the Fade is done the method returns true. After every fade you need to reset the variable t to 0.
Good Luck!