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 are like sending direct messages to objects instead of syncing variable values.
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 on Start Tutorial page.
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 we can open the bindings window and find a Methods
tab used for command setup. There we can find a method called ReceiveCommand
and beside it, an icon describing who the command will be sent to (only to the objects' authority or alternatively to all Clients).
In the game view in Play mode, commands can be sent to other Entities via the right click button. An exclamation mark asset will pop up above the right-clicked Entity for all Clients.
If we were to set this command to Authority Only
then only the objects' authority would receive this method call.
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 how replication works for each.