• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by VMask25 · May 24, 2017 at 07:40 AM · networkingnetworkvariablespassing

Networking Unity, I need to pass a simple variable value between Client and Server.

Help, I want to create a multiplayer game in w$$anonymous$$ch the player ONE can choose one of the four attacks, and when he press the button, in the device of the other player (player TWO) the gameobject of the player ONE do the animation and do damage to the player TWO. (like all Pokemon games) How can I pass variables values between the two devices and then do somet$$anonymous$$ng? I found somet$$anonymous$$ng about the SyncVar but I didn't understand how they works and if they are what I need to do that. Please, if you can, show me some script examples that do that.

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by XxSimBaaxX · May 24, 2017 at 09:31 AM

[SyncVar] is a command that synchronizes the variable between the client and the server (but not with the rest of the clients), its written right before the variable itself,example: [SyncVar] int example1; that will synchronize every value change with the server. if you want to synchronize the value between two clients then you have to synchronize the value from client one to the server and then from server to client two and you can do that by the [ClientRpc] command, example:

 //t$$anonymous$$s will sync the variables value from client to server
 [SyncVar] int example1;
 
 void Update ()
 {
     RpcSyncVarWithClients (example1);
 }
 
 //t$$anonymous$$s will sync var from server to all clients by calling the "SyncVarWithClientsRpc" funtion on the clients with the value of the variable "varToSync" equals to the value of "example1"
 [ClientRpc]
 void RpcSyncVarWithClients (int varToSync)
 {
     example1 = varToSync;
 }

note: ClientRpc functions have to start with "Rpc" like: void RpcExample () I hope that helped you :)

Hamza Odeh

Comment

People who like this

0 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image VMask25 · Jun 02, 2017 at 03:45 PM 0
Share

Thank you so much. I have another big problem. On the computer it works, but I have to do it for android devices. So I used the IP address 192.168.43.1 as HOST IP and the port 6321. It works only if I use an hotspot connection between the two devices and only if the HOST device is the device which offer the hotspot....I don't understand why, I want it works with my WIFI connection, and not with the hotspot...

avatar image XxSimBaaxX · Jun 02, 2017 at 11:33 PM 0
Share

@VMask25 I just noticed that The note at the end is incorrect, the right one is that the Rpc has to be written at the start, like: void RpcExample () and not at the end, like: void ExampleRpc () Sorry about that little mistake, everything shall work alright now :)

avatar image Alexiosiko · Mar 30, 2022 at 05:51 PM 0
Share

I love you so much

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UNET | How to use network messages? 1 Answer

Network Soccer Ball Position jitter, sending transform position late? 0 Answers

UNET AssetID 0000 zero 0 Answers

PLS recommend plugins for networking/sever which ONLY work for authentication + storing player info. 0 Answers

how to spawn a player prefab on a server 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges