Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Play animation single time and move back to default animation

Discussion in 'Animation' started by siddharth3322, Apr 10, 2016.

  1. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,042
    As per my title suggest I want to play my other animation single time and then move back to default animation. Here I give my actual example so that you will become more clear.

    Screen Shot 2016-04-10 at 9.17.11 PM.png

    Here in above image, "BabyGrayMainAnim" is my default animation and "BabyGraySwatAnim" is my other animation that I want to play. In this, "BabyGraySwatAnim" I want to play single then my default animation play as normal. At present I have set bool condition for this and written following code:

    Code (CSharp):
    1.      public void HitFlyingBirds ()
    2.      {
    3.          if (myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("BabyGraySwatAnim"))
    4.              return;
    5.          myAnimator.SetBool ("IsSwat", true);
    6.          StartCoroutine (RunBabyGrayMainAnimation ());
    7.      }
    8.      IEnumerator RunBabyGrayMainAnimation ()
    9.      {
    10.          yield return new WaitForSeconds (1f);
    11.          myAnimator.SetBool ("IsSwat", false);
    12.      }
    But using Enumerator for this purpose is not that much good as per my understanding. I want some better way to implement same thing. If you want more information then ask me for it. Please give some suggestion for this.
     
  2. TimGS

    TimGS

    Joined:
    Apr 24, 2014
    Posts:
    70
    Last edited: Apr 11, 2016