Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by ivomarel · Oct 10, 2012 at 03:15 AM · networksynchostlan

What is the easiest way to set up a LAN-game?

Hey guys,

I have been trying to figure this out, since I am trying to create a very simple LAN-game, for testing purposes and to eventually create an AI from playing the game myself.

Here's my problem: What I am building is an RTS game, which means that synchronization is critical.

In my code-example (see under) I wrote some code which handles perfect synching, the example is just a cube changing color, but ofc this could be anything.

     //This function is called from a button-press.
     public void OnCubeColorChange(string color) {
         networkView.RPC("ServerSetCubeColor", RPCMode.All, color);
     }
     
     //We use this function, since we can't send a Color-variable in an RPC
     Color HexToColor(string hex)
     {
         byte r = byte.Parse(hex.Substring(0,2), System.Globalization.NumberStyles.HexNumber);
         byte g = byte.Parse(hex.Substring(2,2), System.Globalization.NumberStyles.HexNumber);
         byte b = byte.Parse(hex.Substring(4,2), System.Globalization.NumberStyles.HexNumber);
         return new Color32(r,g,b, 255);
     }
     
     //All users receive this message, but only the host will execute any code
     [RPC]
     void ServerSetCubeColor(string cubeColor) {
         if(Network.isServer) {
             networkView.RPC("SetCubeColor", RPCMode.All, cubeColor);
         }
     }
     
     //All users receive this message and it is certain that everyones cube is the same color.
     [RPC]
     void SetCubeColor(string cubeColor) {
         GetComponent<MeshRenderer>().material.color = HexToColor(cubeColor);    
     }

So when someone presses the button, it will send out a message to all users (RPCMode.Server did not call anyone, so I couldn't use that) and only the host (checked by Network.isServer) will send out a message to everyone again, which actually changes the color of the cube.

Perfectly synced, but the host will always have that 0.05 second advantage over the other users, making this a little bit unfair. A second thing is that sending a message out to everyone when actually only the host should get it, seems a little inefficient.

So my final question is: Does this code make sense to people? I feel like it's not the most logical way, but I would prefer not to work with a Master server, since it seems like quite a bit of hassle which might not be necessary.

Thanks for any help!

Cheers,

Ivo

P.S. I am aware of the fact that it's not neat coding to put the server-function in the Cube-object itself.

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

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

absolute beginner Multiplayer 0 Answers

How fast do Syncvars synchronize? 1 Answer

Network Client Connecting with different Maps 3 Answers

Trying to Connect a Remote Computer from a Different ISP 0 Answers

How to sync a sprite change to other clients? 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