How To Make Main Menu Fade in

Hey, so I wanted to make my main menu fade in at the beginning of the game when it starts. I tried using an animation to change the panel’s image alpha color to do the fade, but it doesn’t fade the main menu buttons and text. Rather it just fades the background image. Thanks for any help

You can add a CanvasGroup component to the canvas. There is an Alpha property in it. Then fade that alpha value over time with a Coroutine.

    IEnumerator DoFadeOut()
    {
        while(canvasGroup.alpha > 0)
        {
            elapsedTime += Time.deltaTime;
            canvasGroup.alpha = Mathf.Clamp01(1.0f - (elapsedTime / fadeTime));
            yield return null;
        }

        yield return null;
    }

It depends how simple or complex you want to go.

You can create a new panel, set it to 100% black, then by code, have it start at 100% alpha, then “fade” down to 0%, which simulates a basic-enough fade

If you want the buttons and text and all that to fade in, possibly at different rates, then youd have to either put all the buttons and text on a tag, load everything of that tag into an array and fade each item of that array individually, for different rates - or create a long list of public variables (or an array of GameObjects, or a array of Buttons and Texts), and fade each of those in, same thing manipulating the alpha.

For an example of a “basic” fade:
C#

public Image fader;

void Start() {
Color alpha = fader.Color;
while(alpha.a > 0f){
//Initally set the alpha of this to 100% so this can take proper effect
alpha.a -= 0.1f;
fader.Color = alpha;
}
}

And then more of an “advanced” fader, of for example buttons in an array, similar idea: also C#

public Button[] buttons;

void Start() {
for(int i = 0; i < buttons.Length - 1; i++){
//Initially set the alpha color of each button in the Editor to 0 so this can take proper effect.
Color alpha = buttons*.color;*

while(alpha.a < 1f){
alpha.a += 0.1f;
buttons*.color = alpha;*
}
}
}
Youll have to import the UI as well, mousing over the “Button” when its underlined in red, and clicking on “Show Solutions”, one option is having it automatically import the UI class.
Also keep in mind THIS IS DANGEROUS the way I did it, because im using loops, even though its in Start (so itll only happen once), it may “stall” as its running through, because its a WHILE loop - youll probably want to put these into functions and call them differently by Invoke, InvokeRepeating, or even manipulating the idea of routines, though generally, the same idea in code apply - youll want to get the current alpha, increase it over some form of time, then make sure you apply it.

Thanks for the replies guys, however I fixed my issue. I decided to just set the panels up so that there’s a “fade in” panel under what I need to fade in the hierarchy and everything else just goes under the fade in panel. Bit of an odd situation, but it works. Used an animation to do the actual fading with Image color. While I have you guys, mind checking out my other question I posted that I’m REALLY stuck on. It involves changing the volume values in a mixer. Link here: http://answers.unity3d.com/questions/1249167/how-to-change-audio-mixer-volumes-in-void-start.html . Thanks again