Skip to content

Instantly share code, notes, and snippets.

@herpdederp
Created June 15, 2020 18:39
Show Gist options
  • Save herpdederp/a2f3e8b0dd1a2bf94bfc54af28c5ce81 to your computer and use it in GitHub Desktop.
Save herpdederp/a2f3e8b0dd1a2bf94bfc54af28c5ce81 to your computer and use it in GitHub Desktop.
private void Update()
{
if (BoltNetwork.IsServer == false) { return; }
if (Input.GetKeyDown(KeyCode.Space))
{
IncreasePlayerCount(1);
}
if (Input.GetKeyDown(KeyCode.L))
{
ShowPlayerCount();
}
}
private void ShowPlayerCount()
{
var session = BoltMatchmaking.CurrentSession as PhotonSession;
if (session != null)
{
var key = "playerCount";
if (session.Properties.ContainsKey(key))
{
Debug.LogFormat("Current Player Count: {0}", session.Properties[key]);
}
}
}
private void IncreasePlayerCount(int value)
{
var session = BoltMatchmaking.CurrentSession as PhotonSession;
if (session != null)
{
var key = "playerCount";
var currentCount = 0;
if (session.Properties.ContainsKey(key))
{
currentCount = (int)session.Properties[key];
}
var updateToken = new PhotonRoomProperties();
updateToken[key] = currentCount + value;
BoltMatchmaking.UpdateSession(updateToken);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment