Search Unity

Fade UI Text in and out before waves of enemies

Discussion in 'UGUI & TextMesh Pro' started by fabianampires, Sep 12, 2014.

  1. fabianampires

    fabianampires

    Joined:
    Mar 30, 2014
    Posts:
    12
    Hi Everyone,

    I'm writing a game in which I have 3 waves of enemies in each level. I want to show a text message before each wave, such as: "Wave 1", "Wave 2", "Wave 3".

    I've followed the Beginner Survival shooter tutorial and created an animation for my text message (turning alpha color from 0 to 255 back to 0 - so the message appears and fades away).

    I have the code below in my wave manager script, before each wave loop:

    Animator anim;


    anim=MessageWaves.GetComponent<Animator>(); //MessageWaves is my UI Text object

    anim.SetTrigger ("WaveMessage");

    yield return new WaitForSeconds(2.0f); //That's how long my animation takes



    Animation set up:
    - My animation's loop is set to false
    - On the animator, according to the tutorial, I've created and set an empty state as default and have a transition that is triggered when I called the "WaveMessage" trigger I defined as a condition to my transition.

    This is working beautifully for the first wave. But the animation doesn't show for the other 2 waves. Any ideas on what could be happening?
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,702
    If you watch the Animator view during play, is it still on the wave message state when the animation ends? If so, then SetTrigger() won't do anything since it's already in that state. Add a transition from the wave message state back to your empty state on Exit Time (i.e., when the fade animation is done).
     
    fabianampires likes this.
  3. fabianampires

    fabianampires

    Joined:
    Mar 30, 2014
    Posts:
    12
    Thank you Tony! I spent hours yesterday trying to solve this via code and it was that simple!
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,702
    Happy to help!
     
    fabianampires likes this.