Search Unity

How to make text fad in and out on load

Discussion in 'Getting Started' started by KyleL144, Aug 9, 2019.

  1. KyleL144

    KyleL144

    Joined:
    Aug 9, 2019
    Posts:
    21
    Hey I am trying to make text fade in and out on load and then load a new scene after the text has faded out , but it is not working for me. I have followed a youtube tutorial on how to achieve this, but it is not working. Am I doing something wrong.

    Here is thew code below:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.SceneManagement;
    7.  
    8. public class copyright : MonoBehaviour
    9. {
    10.     public Text copyright;
    11.     public string loadLevel;
    12.  
    13.     IEnumerator Start()
    14.     {
    15.         copyright.canvasRenderer.SetAlpha(0.0f);
    16.  
    17.         FadeIn();
    18.         yield return new WaitForSeconds(2.5f);
    19.         FadeOut();
    20.         yield return new WaitForSeconds(2.5f);
    21.         SceneManager.LoadScene(loadLevel);
    22.     }
    23.     void FadeIn()
    24.     {
    25.         copyright.CrossFadeAlpha(1.0f, 1.5f, false);
    26.     }
    27.     void FadeOut()
    28.     {
    29.         copyright.CrossFadeAlpha(0.0f, 2.5f, false);
    30.     }
    31. }
    1.png 2.png 3.png

    Any Help Appreciated and thanks in advance​
     
  2. KyleL144

    KyleL144

    Joined:
    Aug 9, 2019
    Posts:
    21
    sorry about the misspelling *fade
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,519
    You should always name your classes with CamelCase. So your "class copyright" should be at least "Copyright", although it's weirdly specific. It would be better to call it "TextFaderBeforeLoading" or something, so you can use it in other situations as well.

    You should never name any properties or variables after the class they are belong to. So the "public Text copyright;" should be "public Text copyrightText;" or something.
     
    KyleL144 likes this.
  4. KyleL144

    KyleL144

    Joined:
    Aug 9, 2019
    Posts:
    21
    Thank you :)