public void PlayerScored(string playerId)
// Read the current value of the "PlayerScores" SyncProperty.
PlayerScores playerScores = roomPropertyAgent.GetPropertyWithName("PlayerScores").GetValue<PlayerScores>();
// Initialize the playerScores object.
if (playerScores == null)
playerScores = new PlayerScores();
bool foundPlayerScore = false;
// If player already have a score, increase it by 1.
foreach (Score s in playerScores.scores)
if (s.playerRemoteId == playerId)
// If player has not scored yet, add a new score for the player and set its value to 1.
ps.playerRemoteId = playerId;
playerScores.scores.Add(ps);
// Modify the "PlayerScores" SyncProperty
roomPropertyAgent.Modify<PlayerScores>("PlayerScores", playerScores);