Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
UnityGamesRoland

How does UNET Attributes work?

Question

Hey guys! I'm currently learning UNET (and networking overall) but I stuck on this. I don't understand when to use which attribute.

Lets say for example: I would like to print out the name of the player who currently joined the room, to the console.

 

Please login or register to see this code.

 

 

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 1

SyncVar variables are synced straight from the server to the client on value change. Syncvar is set to the client at each end frame. Your player name is logged out twice, because you're sending it to the server and your player local player/host is both, you can check if player is an local player or not.

Edit:

You could do something like this:
 

Please login or register to see this code.

 

Edited by Andrus99

Share this post


Link to post
Share on other sites

  • 0

It's most likely either being called locally AND over the network or its being called by the host (you) and the client(you). I don't use unet but I am familiar with networking. Normally you would specify who should be calling it and/or who should be receiving it, but your code, I'm not seeing who is actually supposed to call it. Sudo:

 

if(isHost) Call();

or 

if(isHost) BroadcastToClients();

Share this post


Link to post
Share on other sites
  • 0

I also just took a look and I could be wrong, but it looks like it would be more of a clientrpc instead of a command

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

If I call an RPC, it is going to happen on every client but individually, not in the server right?

Also any examples for the command? When should it be used? I'm a bit confused about networking :|

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

ClientRpc will be called on your  host aswell, [Client] attribute will not

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...