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 yoloswaggins · Oct 16, 2014 at 02:30 AM · networkingnetworkrpcserialize

Networking Unity can't get players on network to change each others variables.

HI all,

recently started networking this week and i'm trying get to get two players prefabs that have been instantiated on the network to communicate but I'm unsure how to do that... I've heard of Serialize and RPC but not sure how to implement it with what I have..

Basically, player1(client) cannot move as the server hasn't updated the client on plaer2s position if player2(server) moves away as the collisionexit wont register over the network, along with any attacks that will effect his health int to kill him. The variables seem unaffected when done over the network..the networkview only picks up the transformation when I want it to pick up the transformation, and access to variables in two of the scripts attached to the opposing player..

Networkmanager.cs

public void StartServer() { Network.InitializeServer (15, 25001, !Network.HavePublicAddress()); MasterServer.RegisterHost (typeName, gameName); } void OnServerInitialized() { Debug.Log("Server Initialized"); //network1.playerBalanceMech (); SpawnPlayer(); } // 2nd part private void RefreshHostList() // refresh active Server Hosting Lists, to join the server { MasterServer.RequestHostList (typeName); } void OnMasterServerEvent(MasterServerEvent msEvent) // { if (msEvent == MasterServerEvent.HostListReceived) hostList = MasterServer.PollHostList (); } private void JoinServer(HostData hostData) { Network.Connect (hostData); } void OnConnectedToServer() { Debug.Log ("Server Joined"); SpawnPlayer2(); } // Game Commands [RPC] public void SpawnPlayer() { // Player 1 Network.Instantiate (player1prefab, pos1.player1Start, Quaternion.identity, 0); } [RPC] public void SpawnPlayer2() { Network.Instantiate (player2prefab, pos2.player2Start, Quaternion.identity, 0); }

Offline, I can access the variables and have the game completed.. however I've never had much experience with this sort of thing.

Example on how I tried to alter p2's variables when p1 collides with him

Player1.cs

     // Network stuffs
     void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
     {
         if (stream.isWriting)
         {
             stream.Serialize(ref moveAfterCollision2.KeyEnabled_N); 
         }
         else
         {
             stream.Serialize(ref moveAfterCollision2.KeyEnabled_N);
     
         }
     }


 public void OnTriggerExit2D(Collider2D coll)
     {
         if (coll.gameObject.tag == "Player2")
         {
             print ("Player 1 left Player 2");
             KeyEnabled_M = true;
             moveAfterCollision2.KeyEnabled_N = true;
         }
     }

This is really hard to explain, but I hope somebody can help! :)

Craig

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

2 People are following this question.

avatar image avatar image

Related Questions

Is there a more flexible method of sending data over network than RPC? 1 Answer

Sending an RPC 1 Answer

Multiplayer Scoreboard Problem. 1 Answer

Failed to connect to master server since days 1 Answer

other players and the server does not receive networkView.RPC 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