Search Unity

Animator SetBool

Discussion in 'Multiplayer' started by BikaYoBadi, Jan 28, 2017.

  1. BikaYoBadi

    BikaYoBadi

    Joined:
    Jan 1, 2016
    Posts:
    50
    I'm trying to play die animation when health reaches zero, but unlike movement animation, die animation only works for host client. I mean, when client killed host client, die animations works for both, but when host client killed client, it only seem to play for a while in host client view; in client, nothing happens. I have tried both clicked and de-clicked the bool in NetworkAnimator component. Here a little part of setbool code. I don't have fully understanding in unet. I'm waiting for advices I really need, thanks in advance.

    Code (CSharp):
    1. public void DecreaseHealth(int _amount)
    2.     {
    3.         //I tried to remove this statement to see, if it works, but it doesn't matter at all
    4.         /*
    5.         if (!isServer)
    6.             return;
    7.         */
    8.  
    9.         if (isDead)
    10.             return;
    11.      
    12.         health -= _amount;
    13.  
    14.         if (health <= 0)
    15.         {
    16.             isDead = true;
    17.             GetComponent<Freezer>().CmdDie();
    18.             anim.SetBool("isDead", isDead);
    19.         }
    20.  
    21.     }
     
  2. BikaYoBadi

    BikaYoBadi

    Joined:
    Jan 1, 2016
    Posts:
    50
    I still need help !!!

    Edit : Finally, I solved it. I moved the anim.set function to the update, and set the variable as syncvar. (I'm talking with myself in this post , this is not good)
     
    Last edited: Jan 29, 2017