Search Unity

Anim.speed bug?

Discussion in 'Animation' started by Aktarus_Neuro, Aug 31, 2020.

  1. Aktarus_Neuro

    Aktarus_Neuro

    Joined:
    Jun 4, 2016
    Posts:
    13
    Hi,

    I have an animation, which I want to be able to pause/play each time I switch a boolean variable to true and make it play until the normalized time of the animation reach that value (increase every iteration by 0.05f). The problem is that it works until the normalized time is around 0.2f (so 20% of the total of the animation) and then stops playing (freeze). Is it a bug or I'm missing something?
    Thanks

    Code (CSharp):
    1.  
    2.     void Start()
    3.     {
    4.         MyAnim = GetComponent<Animator>();
    5.         MyAnim.Play("MyAnimation");
    6.         MyAnim.speed = 0;
    7.     }
    8.  
    9. void Update()
    10.     {
    11.         float_var = MyAnim.GetCurrentAnimatorStateInfo(0).normalizedTime;
    12.         Debug.Log("floatVar update: " + float_var);
    13.  
    14.         if (boolVariable)
    15.         {
    16.             MyAnim.speed = 1;
    17.             newValue += 0.05f;
    18.             boolVariable = false;
    19.         }
    20.  
    21.         if (float_var > newValue)
    22.         {
    23.             MyAnim.speed = 0;
    24.         }
     
  2. Aktarus_Neuro

    Aktarus_Neuro

    Joined:
    Jun 4, 2016
    Posts:
    13
    Nevermind. Not a bug. It was a problem of script being detached from the object