Skip to content

Commit 5f8e2f8

Browse files
docs: Update messaging-system.md (#377)
This example wont work without inherit from NetworkedBehaviour which is not mentioned anywhere. I had to decompile the dll to figure this out.
1 parent a456d12 commit 5f8e2f8

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

docs/_docs/the-basics/messaging-system.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,36 @@ void MyMethod(int myInt)
2323

2424
#### Convenience Example
2525
```csharp
26-
private void OnGUI()
27-
{
28-
if (GUILayout.Button("SendRandomInt"))
29-
{
30-
if (IsServer)
31-
{
32-
InvokeClientRpcOnEveryone(MyClientRPC, Random.Range(-50, 50));
33-
}
34-
else
35-
{
36-
InvokeServerRpc(MyServerRpc, Random.Range(-50, 50));
37-
}
38-
}
39-
}
40-
41-
[ServerRPC]
42-
private void MyServerRPC(int number)
43-
{
44-
Debug.Log("The number received was: " + number);
45-
Debug.Log("This method ran on the server upon the request of a client");
46-
}
47-
48-
[ClientRPC]
49-
private void MyClientRPC(int number)
26+
public class Example : NetworkedBehaviour
5027
{
51-
Debug.Log("The number received was: " + number);
52-
Debug.Log("This method ran on the client upon the request of the server");
28+
private void OnGUI()
29+
{
30+
if (GUILayout.Button("SendRandomInt"))
31+
{
32+
if (IsServer)
33+
{
34+
InvokeClientRpcOnEveryone(MyClientRPC, Random.Range(-50, 50));
35+
}
36+
else
37+
{
38+
InvokeServerRpc(MyServerRpc, Random.Range(-50, 50));
39+
}
40+
}
41+
}
42+
43+
[ServerRPC]
44+
private void MyServerRPC(int number)
45+
{
46+
Debug.Log("The number received was: " + number);
47+
Debug.Log("This method ran on the server upon the request of a client");
48+
}
49+
50+
[ClientRPC]
51+
private void MyClientRPC(int number)
52+
{
53+
Debug.Log("The number received was: " + number);
54+
Debug.Log("This method ran on the client upon the request of the server");
55+
}
5356
}
5457
```
5558

0 commit comments

Comments
 (0)