Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Class MyNetworkManager
- {
- void Awake()
- {
- Networking.onData += OnDataRecieved; //Adding the custom thing to do on receiving data
- Networking.onPlayerDisconnect += OnLeaveGame; //Adding the custom thing to do when a player leaves
- }
- //The custom thing I want to do with data received
- void OnDataRecieved (NetworkInfo Info, object[] Data)
- {
- //Info contains networking information such as who sent the data
- byte OperationCode = Data [0];
- byte UnitID = Data[1];
- if (OperationCode == 0)
- {
- Vector2 Position = Data [2];
- byte Health = Data [3];
- GetUnit (UnitID).SetPosition (Position);
- GetUnit (UnitId).SetHealth (Health);
- }
- if (OperationCode == 1)
- {
- GetUnit (UnitID).Explode ();
- }
- }
- //The custom thing I want to do when a player leaves a game
- void OnLeaveGame (NetworkInfo)
- {
- object[] SendData = object [] {1, MyUnit.ID};
- SendMessage (Receivers.All, SendData); //This triggers onData on receiving clients
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement