• 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
0
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 which 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 something? I found something 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
Add comment
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
0
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:

 //this will sync the variables value from client to server
 [SyncVar] int example1;
 
 void Update ()
 {
     RpcSyncVarWithClients (example1);
 }
 
 //this 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
Add comment · 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

@V$$anonymous$$ask25 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 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.

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

iOS Networking 1 Answer

[UNET] Transform sycing problem,[UNET] TRANSFORMATION SYCING PROBLEMS 0 Answers

How do I properly deal with Internal_CloneSingle can only be called from the main thread 0 Answers

Network Multiple Cameras 4 Answers

[UNET] Client cannot call [Command]s, only the host can 1 Answer


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