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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to set object's rotation to 0 if animation is not finished

Discussion in '2D' started by MitjaHD, May 12, 2020.

  1. MitjaHD

    MitjaHD

    Joined:
    Sep 30, 2018
    Posts:
    64
    I have a sword with animator and when I press Return the animation plays (rotation on z from 0->-120->0). I can swap weapons however and if I do so when the rotation is not finished, my sword is stuck somewhere between 0 and -120 when I swap back to sword. Even if I play the animation again (the animation plays) the sword doesn't go back to 0. When I swap the weapons I disable the gameobject, so the animator on sword is disabled as well. Setting rotation via script (OnEnabled) didn't work. also changing rotation midgame on Inspector doesn't work. Not sure how animations work.
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @MitjaHD

    ...without code, pretty impossible to say for sure what is going on.
     
  3. MitjaHD

    MitjaHD

    Joined:
    Sep 30, 2018
    Posts:
    64
    Code (CSharp):
    1. void Update()
    2.     {
    3.         timer -= Time.deltaTime;
    4.  
    5.         if (Input.GetKey(KeyCode.Return) && timer<0f)
    6.         {
    7.             animator.SetTrigger("Zamah");
    8.             timer = 1f;
    9.         }
    10.     }
    zamah.png