- Home /
Fade in/out a GameObject
I have a GameObject and I want to instantiate it but I need to make a fade in (from transparent to full color) and then, when I destroy it, make a fade out.
The object is an Empty GameObject called Enemy with several 2d Toolkit Sprites as childs (head, body, arms, legs, etc).
Can this be done?
Comment
Answer by NoseKills · Mar 13, 2015 at 12:44 PM
Get the SpriteRenderer Components of the sprites you want and change the alpha in their .color property. Something like
public SpriteRenderer[] renderers;
void Start() {
renderers = GetComponentsInChildren<SpriteRenderer>();
}
void Update()
{
Color alphaFadedColor = Color.white;
// modify alpha
// create your own time based algorithm and start it when you want the fade to start
alphaFadedColor.a = Time.realtimeSinceStartup / 10f;
foreach (SpriteRenderer renderer in renderers)
{
renderer.color = alphaFadedColor;
}
}
Your answer
Follow this Question
Related Questions
How do I make the screen fade when it goes into the next level? 0 Answers
Fade In / Out UI Image 3 Answers
Fade out sprite on click 4 Answers
Fade logo before main menu 2 Answers
Changing a GUITexture's alpha gives me no effect in game. 0 Answers