SHOW:
|
|
- or go back to the newest paste.
1 | public Class MyNetworkManager | |
2 | { | |
3 | void Awake() | |
4 | { | |
5 | Networking.onData += OnDataRecieved; //Adding the custom thing to do on receiving data | |
6 | Networking.onPlayerDisconnect += OnLeaveGame; //Adding the custom thing to do when a player leaves | |
7 | } | |
8 | ||
9 | //The custom thing I want to do with data received | |
10 | - | void OnDataRecieved(MessageInfo Info, object[] Data) |
10 | + | void OnDataRecieved (NetworkInfo Info, object[] Data) |
11 | { | |
12 | //Info contains networking information such as who sent the data | |
13 | byte OperationCode = Data [0]; | |
14 | byte UnitID = Data[1]; | |
15 | if (OperationCode == 0) | |
16 | { | |
17 | Vector2 Position = Data [2]; | |
18 | byte Health = Data [3]; | |
19 | GetUnit (UnitID).SetPosition (Position); | |
20 | GetUnit (UnitId).SetHealth (Health); | |
21 | } | |
22 | if (OperationCode == 1) | |
23 | { | |
24 | GetUnit (UnitID).Explode (); | |
25 | } | |
26 | } | |
27 | - | void OnLeaveGame |
27 | + | |
28 | //The custom thing I want to do when a player leaves a game | |
29 | void OnLeaveGame (NetworkInfo) | |
30 | { | |
31 | object[] SendData = object [] {1, MyUnit.ID}; | |
32 | SendMessage (Receivers.All, SendData); //This triggers onData on receiving clients | |
33 | } | |
34 | } |