CanvasGroup For Fading?

This is amazing! I’ve tried all 3 solutions:

  1. The one in the lecture
  2. The CrossFadeAlpha method
  3. This “Canvas Group” method

The Canvas Group method is the best because:

  • It’s most intuitive to set up
  • It requires the simplest code
  • It allows the user to click around as it fades (the user doesn’t have to wait for the fade to finish in order to click)

For anyone wondering how to replicate:

  1. In Unity, in the 01a Start scene, click on Canvas

  2. Click Add Component, then add the “Canvas Group” component

  3. Set alpha to 0

  4. Add Component, make a script, code below (don’t forget to add in the UnityEngine.UI too):

     public float fadeInDelay;
     private CanvasGroup canvasGroup;
    
     void Start()
     {
         canvasGroup = GetComponent<CanvasGroup>();
     }
    
     void Update()
     {
         canvasGroup.alpha += Time.deltaTime / fadeInDelay;
     }
    

Hope that helps and thanks again @BlackPhi for finding this!
-Blaine

2 Likes