- Home /
While fading object out, it turns black.
Hi everyone. Learning coder here. I have taken some sample code I've found around the forums and tried to implement a fade-in with a specified wait time first. The fade-in works, but the object is black. I have a feeling it has something to do with color.a, but I can't find what is wrong in the coding. Any help or fixed samples would be much appreciated. My code is below. Thanks.
{
public float waitTime = 3;
float fadeSpeed = 0.01f;
Color color;
void Awake()
{
color.a = 0;
renderer.material.color = color;
StartCoroutine(WaitTime());
}
void Update()
{
if(color.a <= 1 && color.a > 0)
{
renderer.material.color = color;
color.a += fadeSpeed;
}
}
IEnumerator WaitTime ()
{
yield return new WaitForSeconds (waitTime);
color.a += fadeSpeed;
}
}
Thanks for the responses. The material is already transparency diffuse. If it matters, the material is a texture I made in photoshop. It has a white background, but disappeared when I put on the transparency diffuse shader. I inserted a line in Update() after color.a += fadeSpeed that states " renderer.material.color = Color.white; " but it turns the object white after its fully visible, as expected. The desired color is white.
ok, is your texture a RGBA or just and RGB? It needs to be RGBA
It is RGB. I figured out how to turn it to RGBA, however, since the object is 3D text, the text is no longer readable when I add the RGBA. Each letter in the text gets the texture and becomes a solid white rectangle.
Ok, so you have made a texture for each letter, correct? Or you have a texture atlas?? Each letter texture would need to have a transparent background. I have never used it, but I believe 3D text just uses a transparent plane for each letter. Do you know the words that you are using?? And is that on your texture? Because if you know the words that you want and that will never change, than there is a much better and more optimized way of doing this.
Answer by highpockets · Mar 08, 2014 at 06:11 AM
It needs a transparent shader. What kind of a shader is on it?
Answer by fifthknotch · Mar 08, 2014 at 06:11 AM
Your code works for me. Make sure the material of the GameObject this code is attached to is also set to Transparency => Diffuse
Your answer
![](https://koobas.hobune.stream/wayback/20220613135703im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fade out a line renderer? 1 Answer
Pull a color out of a Color.Lerp fade 1 Answer
Color lerp once? 2 Answers
How to change the alpha element of particles/additive color? 1 Answer
How to vertex colour a single instance of a GameObject? 1 Answer