Search Unity

Question Trying to sync two animations

Discussion in 'Animation' started by P_e_t_a_c_h_e_k, Aug 14, 2021.

  1. P_e_t_a_c_h_e_k

    P_e_t_a_c_h_e_k

    Joined:
    Dec 26, 2017
    Posts:
    26
    Hello. I am trying to sync two 2D animations. There is "Main" animation, and there is "Assistant animation." They are completely the same (in size and in essence). The script is attached to the object with the main animation:

    Code (CSharp):
    1.  
    2. public class Main: MonoBehaviour
    3. {
    4.     public GameObject obj;
    5.     private void OnMouseEnter()
    6.     {
    7.         obj.GetComponent<SpriteRenderer>().enabled = true;
    8.         obj.GetComponent<Animator>().enabled = true;
    9.         obj.GetComponent<Outline>().Sync();
    10.     }
    obj is the Main child

    Script "Assistant animation"(child):
    Code (CSharp):
    1.  
    2. public class Assistant: MonoBehaviour
    3. {
    4.     public Animator Thisanimator;
    5.     public Animator Mainanimator;
    6.     public void Sync()
    7.     {
    8.         Thisanimator.Play(0, 0, Mainanimator.GetCurrentAnimatorStateInfo(0).normalizedTime);
    9.  
    10.     }
    11.     private void Update()
    12.     {
    13.  
    14.         Thisanimator.Play(0, 0, Mainanimator.GetCurrentAnimatorStateInfo(0).normalizedTime);
    15.     }
    16. }
    The problem is that Assistant animation is always one frame behind ... I can't fix that at all. And I really need your help.
     
    Last edited: Aug 14, 2021