So my 2D characters turn by setting flipX on Sprite Renderer. I'm trying to turn them on other clients, but sprite is turning only on local client. And only host turns for all clients.

Here's my code:

RpcTurnChar(GetComponent<SpriteRenderer>().flipX, this.gameObject);

. . .    

void RpcTurnChar(bool flip, GameObject plr)
    plr.GetComponent<SpriteRenderer>().flipX = flip;

What am I doing wrong?

  • \$\begingroup\$ Why are you trying to send flip data? You could simply put a check that will flip the sprite on client side, reducing data usage between clients. Something like: if(( position.x - previousPosx ) < 0 ){ flip = true; } else { flip = false; } previousPosx = position.x; \$\endgroup\$ – John Hamilton Nov 28 '17 at 11:57
  • 1
    \$\begingroup\$ My characters turn by looking at player's cursor, so I have to check where the cursor is on the client side and send flip data to server. \$\endgroup\$ – KiRa937 Nov 28 '17 at 14:05
  • \$\begingroup\$ Ah, that makes sense. Though if your game is anything like Soldat, you could use some other data like weapon angle to determine which way the players are looking. Anyway, I'm just trying to give you more options ;) \$\endgroup\$ – John Hamilton Nov 29 '17 at 4:56

[ClientRpc] functions are only called from the host. For the Client to send to the Host, you need a [Command] function, or serialize a variable.

  • 1
    \$\begingroup\$ Thanks! I've added Cmd function with Rpc one inside. Now it works fine! \$\endgroup\$ – KiRa937 Nov 28 '17 at 21:20
  • \$\begingroup\$ Great! Don't forget to upvote and accept the answer if it solved your problem. Happy coding! \$\endgroup\$ – Stephan Nov 28 '17 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.