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 its 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 affecting 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 how replication works for each.