6. Network Commands
Last updated
Last updated
This scene will show you how easy it is to set up Networking in your Unity project and send Network Commands to other clients. Network Commands is like sending a direct message to another player, without anyone else knowing.
In this example each client has one character they can control with click to move input. They can right-click on another Entity to send a command and that Entity will instantiate an Exclamation mark above their head.
In the Hierarchy of the Scene you can see three core Prefabs:
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail in Exploring the Network Playground.
Coherence Entity
is the prefab that will change per Scene with different functionality. It has a standard CharacterController
and Rigidbody
as well as an Agent
script which will handle movement functionality through the Input Manager
in the Core Scene Setup
prefab.
Coherence Entity
can send commands to other entities through the Coherence Handler
component. In the coherenceSync component, small "lightning bolt" icons are displayed next to the tick boxes for the syncable properties. These icons signify that they are public methods rather than singular variables and that these methods can be called through the Coherence Handler
Event System, either to send or receive commands.
In the game view in Play mode, Commands can be sent to other entities via the right click button. An exclamation mark asset should pop up above the right-clicked entity, but only for the sending and the receiving client. No other clients will be made aware of this.
You can build this Scene via the Build Settings. Run the local Replication Server through the Window -> Coherence -> Settings window and see how it works. You can try running multiple clients rather than just two and see replicating for each.