Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

[Solved] Looping on an animation

Discussion in 'Animation' started by Boogafreak, Jan 9, 2019.

  1. Boogafreak

    Boogafreak

    Joined:
    Oct 2, 2017
    Posts:
    32
    Hi,

    Please help if you can :
    I have a task and there seems to be several ways to go at it, but I'm getting confused on how to do it --
    I need to move game objects 90*X pixels, where X is an integer between 1 and 9 (this depends on board situation). The animation graph is linear (constant speed).

    I can think of :
    1. Making 9 animations, one for each movement, but that seems bad practice..
    2. Loop X times on same animation - Can't find a good explanation on how to do this without waiting for Idle mode each time, which may break animation fluidity..
    3. Place this X integer in an animation parameter and use it somehow (how??)

    Any Advice would help.
    Booga.
     
  2. Boogafreak

    Boogafreak

    Joined:
    Oct 2, 2017
    Posts:
    32
    Well, for all it may concern, I combined #2 and #3 into a working scheme :
    1. Place an integer parameter ("loop_times")to the animation.
    2. When you want the animation to start looping, set it to loop times in code (using animator.SetInteger())
    3. Place a condition of (loop times > 0) to get out of idle to the animation.
    4. On the animation state, implement OnStateEnter() and reduce the number of loops on "loop_times" parameter :
    animator.SetInteger("fall_loops", animator.GetInteger("fall_loops") - 1);

    Hope this helps anyone else :)
    Booga.