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

How to set play time for an animation?

Discussion in 'Animation' started by yepfuk, Oct 28, 2016.

  1. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    67
    Hi,

    I want to set specific time to animations. For example, I have weapon reload animation, this animations default play time is 3 seconds. But I want to play this animation for 2 seconds or any specific time. Is this possible?
    I try to setting speed for achieve this but I can't figure it out with speed.

    Any suggestions? Thank you...
     
  2. Kwel

    Kwel

    Joined:
    Jun 9, 2014
    Posts:
    80
    I don't know if there is something built in for that but I guess even the "speed" parameter should do..
    Assuming you know the "defaultLength" and the "targetLength" of your animtion, you should get :

    Code (CSharp):
    1. float targetSpeed = targetLength / defaultLength;
    Hope it helps.
     
    yepfuk likes this.
  3. GrischaG

    GrischaG

    Joined:
    Apr 26, 2013
    Posts:
    40
    Hi,

    you can use .speed = 0.5f; for example. In this case your animation should run for 6 seconds.
    If you want to play an animation backwards (speed < 0) don´t forget to set the startframe to the end of your animation.
     
    yepfuk likes this.