Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animations only appear on client

Discussion in 'Multiplayer' started by wholast710, May 1, 2022.

  1. wholast710

    wholast710

    Joined:
    Feb 11, 2018
    Posts:
    24
    Hi everyone, there is an animation where the player dances when he presses the button, but this is only visible to the player, other users cannot see it, where am I going wrong?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Mirror;
    5.  
    6. public class AnimDans : NetworkBehaviour
    7. {
    8.     public Animator anim;
    9.     [SyncVar] public int animasyonid = 0;
    10.     void Start()
    11.     {
    12.         anim = gameObject.GetComponent<Animator>();
    13.  
    14.  
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.  
    20.  
    21.     {
    22.         if (isLocalPlayer)
    23.         {
    24.             if (Input.GetKeyDown(KeyCode.Alpha1))
    25.             {
    26.                 animasyonid = 1;
    27.             }
    28.  
    29.  
    30.             if (Input.GetKeyDown(KeyCode.Alpha2))
    31.             {
    32.                 animasyonid = 2;
    33.             }
    34.  
    35.             if (Input.GetKeyDown(KeyCode.Alpha3))
    36.             {
    37.                 animasyonid = 3;
    38.             }
    39.  
    40.             if (Input.GetKeyDown(KeyCode.Alpha4))
    41.             {
    42.                 animasyonid = 4;
    43.             }
    44.  
    45.  
    46.             if (Input.GetKeyDown(KeyCode.Alpha5))
    47.             {
    48.                 animasyonid = 5;
    49.             }
    50.  
    51.  
    52.  
    53.        
    54.  
    55.             if (Input.GetKey(KeyCode.W))
    56.             {
    57.                 animasyonid = 0;
    58.             }
    59.             if (Input.GetKey(KeyCode.A))
    60.             {
    61.                 animasyonid = 0;
    62.             }
    63.             if (Input.GetKey(KeyCode.S))
    64.             {
    65.                 animasyonid = 0;
    66.             }
    67.             if (Input.GetKey(KeyCode.D))
    68.             {
    69.                 animasyonid = 0;
    70.             }
    71.  
    72.             if (animasyonid == 0)
    73.             {
    74.                 anim.Play("Grounded");
    75.             }
    76.             else if (animasyonid == 1)
    77.             {
    78.                 anim.Play("Hiphophu");
    79.  
    80.             }
    81.             else if (animasyonid == 2)
    82.             {
    83.                 anim.Play("Chicken");
    84.  
    85.             }
    86.             else if (animasyonid == 3)
    87.             {
    88.                 anim.Play("Macerana");
    89.  
    90.             }
    91.             else if (animasyonid == 4)
    92.             {
    93.                 anim.Play("SillyDance");
    94.  
    95.             }
    96.             else if (animasyonid == 5)
    97.             {
    98.                 anim.Play("Twist");
    99.             }
    100.         }
    101.  
    102.    
    103.  
    104.     }
    105.  
    106. }
    107.  
     
  2. wholast710

    wholast710

    Joined:
    Feb 11, 2018
    Posts:
    24