How to make a 3D object fade out?
I know there's a bunch of questions already answered about this topic, however I am still not able to make it so I'll try to ask by myself:
I need my 3D object to slowly disappear and I just don't understand, why this script doesn't work?
public class BrokenPieceBehivour : MonoBehaviour {
private Material mat;
void Start () {
mat = gameObject.GetComponent<MeshRenderer>().material;
}
void Update () {
while (mat.color.a > 0)
{
Color newColor = mat.color;
newColor.a -= Time.deltaTime;
mat.color = newColor;
gameObject.GetComponent<MeshRenderer>().material = mat;
}
}
}
When I add the script to an kind of 3D gameObject - nothing is happening. I use standard shader - is that wrong? Or do I use the right component - the MeshRenderer?
Thanks for any help :)
Answer by malgi · Nov 06, 2016 at 11:33 PM
Yup! Shader has to be transparent. Btw there is also no need to use while cycle in Update function!
Your answer
Follow this Question
Related Questions
Apply a dithering transparency effect to a mesh with a dissolve effect 1 Answer
Problem with Fading out Objects via setting rendering Modes to Transparent instead of Opaque 1 Answer
Making A Model Transparent/Fade? Unity-chan etc... 3 days no results! 0 Answers
Changing sprite alpha on all prefab clones 0 Answers
Problem with Z testing??? 1 Answer