7. Team based
Last updated
Last updated
This scene will show you how coherence can be used to make a basic team based game.
In this example each client has one character they can control with click to move input. When connecting the player will be prompted to select a team they wish to join.
This selection will be synced via a TeamIndex
field in the Sample Team Agent
component.
The Target Area
object is a unique gameobject that is shared among clients and moves around the grid, specifying a particular part of the field every time it jumps. When arriving at it's final position this object checks which team has the most players inside the specified area and awards that team a point.
The team colors and score are managed by another unique object called Team Assigner
. This object has a synced string variable called encodedScores
which is used to sync the team scores between clients.
Because both the Team Assigner
and Target Area
are persistent we can disconnect from the server and the game state will be preserved as long as the server is alive, even if no clients are connected at all.
Notice that the number of teams and their colors, set in the Team Assigner, are not synced. This means it could be possible to create different clients with different colors without them effecting each other.
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.