Search Unity

Problem with multiplayer flip player 2d [clientRpc]

Discussion in 'Multiplayer' started by PedroMBP, Jun 7, 2017.

  1. PedroMBP

    PedroMBP

    Joined:
    Feb 25, 2017
    Posts:
    21
    Hi everyone, I'm talking about Brazil, I apologize for my English!

    I am trying to make a game in multiplayer 2d, but I have a doubt that would be in the flip of the player!

    The players can not see each other, and are only spawned when the two are connected in the room, I will leave my code below, thank you from now on!
    I apologize if the code does not make sense because I am a beginner in the area of multiplayer, and I could not find good tutorials!

    SCRIPT HERE!

    Code (CSharp):
    1. public class PlayerBehaviour : NetworkBehaviour {
    2.  
    3. [SyncVar] public bool positionFlip;
    4.  
    5.  
    6. void FixedUpdate (){
    7.  
    8. if (speed < 0) {
    9.  
    10. if (isServer) {
    11. RpcFacingCallback (true);
    12.  
    13. } else {
    14. CmdFacingCallback (true);
    15.  
    16. }
    17. audio.clip = WalkSound;
    18. if (InAndroid == true) {
    19. isRunning = true;
    20. }
    21.  
    22. }
    23. if (speed > 0) {
    24.  
    25.  
    26. audio.clip = WalkSound;
    27. if (InAndroid == true) {
    28. isRunning = true;
    29. }
    30.  
    31. if (isServer) {
    32. RpcFacingCallback (false);
    33.  
    34. } else {
    35. CmdFacingCallback (false);
    36.  
    37. }
    38.  
    39. }
    40.  
    41. }
    42. [ClientRpc]
    43. void RpcFacingCallback (bool positionToFlip){
    44.  
    45.  
    46.  
    47. positionFlip = positionToFlip;
    48.  
    49. if (positionFlip) {
    50. transform.localEulerAngles = new Vector3 (0, 180, 0);
    51. }else{
    52. transform.localEulerAngles = new Vector3 (0, 0, 0);
    53. }
    54.  
    55.  
    56.  
    57. }
    58.  
    59. [Command]
    60. void CmdFacingCallback (bool positionToFlip){
    61.  
    62.  
    63.  
    64. positionFlip = positionToFlip;
    65.  
    66. if (positionFlip) {
    67. transform.localEulerAngles = new Vector3 (0, 180, 0);
    68. } else {
    69. transform.localEulerAngles = new Vector3 (0, 0, 0);
    70. }
    71.  
    72.  
    73.  
    74. }
     
    Last edited: Jun 7, 2017
  2. PedroMBP

    PedroMBP

    Joined:
    Feb 25, 2017
    Posts:
    21
    I apologize if there is any mistake, I am new to this forum!