Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 slatius · Sep 26, 2011 at 06:56 PM · networkrpc

Deleting client objects if internet connection was lost...

Ok this code seams to work... now I'm wondering if this is the best way. Please feel free to comment my code xD

 private var clients : Array;

private var sendEnabled : boolean = true;

@RPC function StopSendingClient(){ sendEnabled = false; }

@RPC function AddClient(networkPlayer : NetworkPlayer){ var add : boolean = true; var counter : int = 0;

 for(counter = 0; counter < clients.length; counter++)
     if(networkPlayer == clients[counter])
         add = false;
 
 if(add){ 
     clients.Add(networkPlayer);
     this.gameObject.networkView.RPC("StopSendingClient", networkPlayer);
 }

}

function SendClient(){ if(sendEnabled) this.gameObject.networkView.RPC("AddClient", RPCMode.Server, Network.player); }

function Start(){ if(Network.isServer) clients = new Array(); else{ sendEnabled = true; InvokeRepeating("SendClient", 0.0, 2.0); } }

function OnGUI(){ if(Network.isServer){ GUILayout.Label(clients.length.ToString()); } }

function OnFailedToConnectToMasterServer(info: NetworkConnectionError){ Network.Disconnect(); MasterServer.UnregisterHost(); MasterServer.ClearHostList(); Debug.Log(info); }

function Update (){ var counter : int = 0; if(Network.isServer){ for(counter = 0; counter < clients.length; counter++){ var connectionPing : int = Network.GetAveragePing(clients[counter]);

         if(connectionPing == -1){
             Debug.Log("Deleting Player through GetAvaragePing");
             Network.RemoveRPCs(clients[counter]);
             Network.DestroyPlayerObjects(clients[counter]);
             clients.RemoveAt(counter);
         }
     }
 }if(Network.peerType == NetworkPeerType.Disconnected)
     Application.LoadLevel("Lobby");

}

function OnDisconnectedFromServer(info : NetworkDisconnection){ Network.RemoveRPCs(Network.player); Network.DestroyPlayerObjects(Network.player);

}

Comment
Add comment · Show 3
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 slatius · Sep 27, 2011 at 12:21 AM 0
Share

come on unity users.....need some help :P

avatar image syclamoth · Sep 28, 2011 at 12:17 AM 1
Share

To start with, that code is pretty hard to read. If you formatted it better, maybe you'd get more interest...

avatar image BerggreenDK · Sep 30, 2011 at 03:06 PM 0
Share

Feel free to CO$$anonymous$$$$anonymous$$ENT YOUR OWN CODE, if we are to spend any time trying to help you @slatius - if you cannot comment it, I dont see any point trying to understand it either.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Crash when sending RPC 2 Answers

client to client ping - NAT punchthrough 1 Answer

RPC Call doesnt get called 2 Answers

RPC , string parameter is sent, but length is 0 1 Answer

RPC setName() not working correctly 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