Search Unity

Animations not syncing

Discussion in 'Multiplayer' started by RBO_, Dec 28, 2017.

  1. RBO_

    RBO_

    Joined:
    Sep 5, 2017
    Posts:
    3
    Hello I have a problem for syncing animations with unity network.
    My idling and running animations are correctly syncing but not the others and I don't get why.





    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3.  
    4. [RequireComponent(typeof(GestureRecognizer))]
    5. [RequireComponent(typeof(Animator))]
    6. public class PlayerController : NetworkBehaviour {
    7.  
    8.     public float smoothAnimationSpeed = 0.15f;
    9.  
    10.     private GestureRecognizer gestureRecognizer;
    11.     private Animator animator;
    12.  
    13.     private float horizontal;
    14.     private float vertical;
    15.  
    16.     void Awake()
    17.     {
    18.         gestureRecognizer = GetComponent<GestureRecognizer>();
    19.         animator = GetComponent<Animator>();
    20.  
    21.         return;
    22.     }
    23.  
    24.     void Start()
    25.     {
    26.         if (isLocalPlayer)
    27.         {
    28.             MainCameraBehavior.target = transform;
    29.         }
    30.     }
    31.  
    32.     void FixedUpdate()
    33.     {
    34.         if(!isLocalPlayer)
    35.         {
    36.             return;
    37.         }
    38.  
    39.         if (horizontal != 0.0f || vertical != 0.0f)
    40.         {
    41.             if (!animator.GetBool("isMoving"))
    42.             {
    43.                 animator.SetBool("isMoving", true);
    44.             }
    45.             animator.SetFloat("horizontal", horizontal, smoothAnimationSpeed, Time.fixedDeltaTime);
    46.             animator.SetFloat("vertical", vertical, smoothAnimationSpeed, Time.fixedDeltaTime);
    47.         }
    48.         else
    49.         {
    50.             if (animator.GetBool("isMoving"))
    51.             {
    52.                 animator.SetBool("isMoving", false);
    53.             }
    54.         }
    55.  
    56.         if(Input.GetButtonDown("Fire1") && !animator.GetBool("isSpelling"))
    57.         {
    58.             animator.SetTrigger("fireball");
    59.         }
    60.  
    61.         if (Input.GetButtonDown("Fire2") && !animator.GetBool("isSpelling"))
    62.         {
    63.             animator.SetTrigger("invisibility");
    64.         }
    65.  
    66.         if(Input.GetButtonDown("Jump") && !animator.GetBool("isSpelling"))
    67.         {
    68.             animator.SetTrigger("protect");
    69.         }
    70.     }
    71.    
    72.     void Update ()
    73.     {
    74.         if (!isLocalPlayer)
    75.         {
    76.             return;
    77.         }
    78.  
    79.         horizontal = Input.GetAxis("Horizontal");
    80.         vertical = Input.GetAxis("Vertical");
    81.  
    82.         if (Input.GetKeyDown(KeyCode.LeftShift))
    83.         {
    84.             gestureRecognizer.Begin();
    85.         }
    86.         if(Input.GetKeyUp(KeyCode.LeftShift))
    87.         {
    88.             gestureRecognizer.End();
    89.         }
    90.  
    91.         return;
    92.     }
    93.  
    94. }