0
\$\begingroup\$

Ok, just found out I can't use [SyncVar] for a sprite gameobject. Furthermore that, [SyncVar] works only on simple values. My question is How would I go about syncing a Sprite over a network?

To explain the context for where I need it, I have a code for players to select an Avatar to play with. Player 'A' and 'B' are able to change their avatars in their own respective device. But the changes made by player 'A' are not reflected in 'B' and vice versa.

So the question is How do I sync a Sprite GameObject?

Note: I am using unity 5.4 and unity's default multiplayer system.

\$\endgroup\$
0
\$\begingroup\$

It seems like you should not be changing the sprite straight away, instead, change some variable that would represent the avatar, and sync that variable over, then it's a matter of making sure that proper avatar sprites show up based on that variable.

So let's say it's a character selection screen, you have Player1 and Player2, their avatar display would have a variable called selectedCharacter, when a player changes character, this updates the selectedCharacter variable and syncs it, now it's up to each client to display a sprite based on that variable.

\$\endgroup\$
  • \$\begingroup\$ Will try it out. From what I understand, you are asking me to have a sprite list and a synced "index" variable using which I can update the sprite in the character selection screen. Will try it and get back with the results \$\endgroup\$ – Gabriel Sep 13 '16 at 9:44
  • \$\begingroup\$ you understood correctly :) \$\endgroup\$ – Brian H. Sep 13 '16 at 9:51
  • \$\begingroup\$ Tried it. Didn't seem to work. Did some research. Just when I thought I had a solution, power went. The power cut has messed up my project. Nothing works as it used to. I will have to start the project all over again. Will post the results after that. Thank you. \$\endgroup\$ – Gabriel Sep 13 '16 at 11:26
  • \$\begingroup\$ I just don't understand it. Its like my unity has a mind of its own. Just like that the project started working and not just that, even the sprite is synced now. Anyways thanks for your answer. \$\endgroup\$ – Gabriel Sep 13 '16 at 12:45

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.